Question: Using Java to create the following classes below. Create a class called Country that has a two-dimensional array with the following data: private String[][] provinces
Using Java to create the following classes below.
Create a class called Country that has a two-dimensional array with the following data:
private String[][] provinces = new String[10][2]();
provinces[0][0]="ab"; provinces[1][0]="bc"; provinces[2][0]="mb"; provinces[3][0]="nb"; provinces[4][0]="nl"; provinces[5][0]="ns"; provinces[6][0]="on"; provinces[7][0]="pe"; provinces[8][0]="qc"; provinces[9][0]="sk";
provinces[0][1]="alberta"; provinces[1][1]="british columbia"; provinces[2][1]="manitoba"; provinces[3][1]="new brunswick"; provinces[4][1]="newfoundland"; provinces[5][1]="nova scotia"; provinces[6][1]="ontario"; provinces[7][1]="prince edward island"; provinces[8][1]="quebec"; provinces[9][1]="saskatchewan";
Create a method called createHashMap() that loops through the provinces array and creates a HashMap whose keys are the province abbreviations and whose values are the province names.
Create another method, called showAllMappings(), that uses an EntrySet Map to display all of the keys and values in the following format:
The abbreviation ab is for the province of Alberta (note: your method must uppercase the first letter and lowercase the rest of the province name).
Create a third method, called showAllMappings2(), that uses a Set and an Iterator to display all of the keys and values in the following format:
The province Alberta has an abbreviation of ab (note: your method must uppercase the first letter and lowercase the rest of the province name).
Create a fourth method, with the signature of public boolean doesAnyProvinceContain(String substring) that returns true if and only if any province contains the substring.
Important: all of your methods must check for null values wherever a null could be a problem.
And Obviously a Main class(tester) if it need one.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
