Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Remembering the names of the countries and their capitals can be very challenging. But children are generally fond of this particular challenge. Help the children
Remembering the names of the countries and their capitals can be very challenging. But children are generally fond of this particular challenge.
Help the children to implement the above task.
Implement the above scenario using a HashMap.
Component Specification: Country
TypeClass
Attributes
Methods
Responsibilities
Country
Map countryMap
Include the getter and setter method.
Note: The class and methods should be declared as public and all the attributes should be declared as private.
Requirement : Add a country and its capital to the HashMap.
As per this requirement, the system should be able to add a country and its capital to the HashMap.
Component Name
TypeClass
Methods
Responsibilities
Add a country and its capital to the HashMap.
Country
public void addString cname, String capname
This method should add a country and its capital to the HashMap. If a country already exists in the countryMap, do not add it again.
Condition: cname is caseinsensitive.
Requirement : Search the capital of a given country.
As per this requirement, the system should be able to search the capital of a country from the HashMap.
Component Name
TypeClass
Methods
Responsibilities
Search the capital of a given country.
Country
public String searchString cname
This method is used to search the capital of a country from the HashMap.
In the UserInterface class,
Createa main method with the menu as described in the sample Input andOutput.
Whenthe user selects option Add,add acountry and its capital into HashMap countryMap.
Whenthe user selects option Search,it should display the capitalof a given country. Ifthe map is empty, it should display "Themap is empty". Ifthe countryis not available in the HashMap, itshould display "Datanot found".
When the user selects option Exit,display the message "Thankyou for using the application" andterminate the program.
Option can take only values to java program
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