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

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 plateMap;

private Set 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 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!