Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a phone bill, which is a HashMap of phone calls organized by phone number and the corresponding sum amount of time (in

You are given a phone bill, which is a HashMap of phone calls organized by phone number and the corresponding sum amount of time (in minutes) for the month to that phone number. They are key/value pairs in the HashMap. You want to find the total number of minutes to phone numbers in a particular area code for the month.

The phone numbers, which are they keys, are in the form xxx-xxx-xxxx and you can extract the area code from the key by calling the method phoneNumber.substring(0,3);

Create the method:

public static int totalAreaCodeMinutes(HashMap map, String areaCode) which finds the sum of minutes in a HashMap of phone calls that month, for the areaCode that is passed in as an argument.

Below is some sample test code which could be used to execute your method, followed by the sample output.

public static void main(String[] args) { HashMap phoneCalls = new HashMap<>(); phoneCalls.put("253-444-3338", 3); phoneCalls.put("253-343-3457", 12); phoneCalls.put("206-235-4346", 14); phoneCalls.put("253-444-3335", 8); phoneCalls.put("206-235-4341", 29); phoneCalls.put("425-235-4342", 5); phoneCalls.put("425-235-4343", 10); System.out.println("minutes to 206: " + totalAreaCodeMinutes(phoneCalls, "206")); System.out.println("minutes to 253: " + totalAreaCodeMinutes(phoneCalls, "253")); System.out.println("minutes to 425: " + totalAreaCodeMinutes(phoneCalls, "425")); } Output: minutes to 206: 43 minutes to 253: 23 minutes to 425: 15

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions

Question

List and briefly explain the fields in an ATM cell.

Answered: 1 week ago