Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Implement the Plates class buildMap function so that it populates the HashMap with the state abbreviations as keys and the counts of how many each appear in the file as values.

Sometimes, the parking attendant will add special notation to help her remember something about a specific entry. There are just non alphabetic characters that she adds to the state - your program should ignore these characters so that an entry like NY* still counts toward the NY plate count.

She is also very inconsistent with how she enters the plates. Sometimes she uses upper case, sometimes lowercase, and sometimes she even uses a mix. Be sure to account for this in your program.

Only add information for plates in New England (Maine, New Hampshire, Vermont, Massachusetts, Rhode Island, and Connecticut).




Plates.java

import java.util.Arrays;

import java.util.HashMap;

import java.util.HashSet;

import java.util.Map;

import java.util.Set;

public class Plates {

private Map<String, Integer> plateMap;

private Set<String> validStates;

public Plates() {

plateMap = new HashMap<>();

validStates = new HashSet<>(Arrays.asList("CT", "MA", "ME", "NY", "RI", "VT"));

}

public void buildMap(String filePath) {

// Implement me...

}

public void printCounts() {

System.out.println("Number of Plates: " + plateMap.keySet().size());

for (Map.Entry<String, Integer> entry : plateMap.entrySet())

System.out.printf("%s -> %s%n", entry.getKey(), entry.getValue());

}

}

Main.java

public class Main {
public static void main(String[] args) {
Plates main = new Plates();
main.buildMap();
main.printCounts();

/*
* The output should be:
*
* Number of Plates: 6
* MA -> 2
* ME -> 3
* CT -> 1
* NY -> 5
* RI -> 5
* VT -> 1
*/
}
}

plates.txt

vt ma ME nY, NY me CA nE Ct

NJ- WA MA ri me ny ny NY *Nj billnye



mAr $RI%

Ri ir RI

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Computer Networking: A Top-Down Approach (7th Edi...
    Computer Engineering
    ISBN:9780133594140
    Author:James Kurose, Keith Ross
    Publisher:PEARSON
    Text book image
    Computer Organization and Design MIPS Edition, Fi...
    Computer Engineering
    ISBN:9780124077263
    Author:David A. Patterson, John L. Hennessy
    Publisher:Elsevier Science
    Text book image
    Network+ Guide to Networks (MindTap Course List)
    Computer Engineering
    ISBN:9781337569330
    Author:Jill West, Tamara Dean, Jean Andrews
    Publisher:Cengage Learning
    Text book image
    Concepts of Database Management
    Computer Engineering
    ISBN:9781337093422
    Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
    Publisher:Cengage Learning
    Text book image
    Prelude to Programming
    Computer Engineering
    ISBN:9780133750423
    Author:VENIT, Stewart
    Publisher:Pearson Education
    Text book image
    Sc Business Data Communications and Networking, T...
    Computer Engineering
    ISBN:9781119368830
    Author:FITZGERALD
    Publisher:WILEY