Answered step by step
Verified Expert Solution
Link Copied!

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
Type(Class)
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 1: 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
Type(Class)
Methods
Responsibilities
Add a country and its capital to the HashMap.
Country
public void add(String 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 case-insensitive.
Requirement 2: 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
Type(Class)
Methods
Responsibilities
Search the capital of a given country.
Country
public String search(String cname)
This method is used to search the capital of a country from the HashMap.
In the UserInterface class,
1. Createa main method with the menu as described in the sample Input andOutput.
2. Whenthe user selects option 1.Add,add acountry and its capital into HashMap countryMap.
3. Whenthe user selects option 2.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".
4. When the user selects option 3.Exit,display the message "Thankyou for using the application" andterminate the program.
5.Option can take only values 1 to 3. java program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions