Question
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
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) { HashMapphoneCalls = 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started