Question
Chapter 21 Assignment There are several tasks in the assignment. Complete them all in the main method of one class. The assignment is about USA
Chapter 21 Assignment
There are several tasks in the assignment. Complete them all in the main method of one class. The assignment is about USA presidents. The last 10 presidents are numbered 36 to 45; 36 being Johnson and 45 being Trump.
Create a map
Create a map object (you choose the map class type) that will have Integer keys and String values. This map will be used to store data for the last 10 presidents.
Write 10 statements (loop not required) to add president data to this map. For example key 36 for value Johnson, key 37 for value Nixon, etc. NOTE: The data in the map must be correct because this map will be used later for a quiz.
Output the size of the map.
To verify that the map was created properly, process it and display the keys and values (see sample run below). NOTE: For full points, you must use the Map.Entry
Create a quiz
Create, run, and score a 5-question presidents quiz as follows:
Make a set that will store Integers. You pick the class type for the set.
Use a while loop to add 5 random numbers to the set. The random numbers must be in the range from 36-45 so we can use them for our map.
Create an iterator that can traverse the set, using the Integers in the set to pose and score the questions (see sample run below).
Use the map to determine if the users responses are correct and score the quiz. After all 5 quiz questions, display the users score on the quiz.
Display alpha president list
Finally, create another data structure from the map that stores just the presidents names in alphabetical order.
Process this new data structure with a foreach loop to display all 10 presidents in alphabetical order as shown in the sample run.
Sample Run
Size of map: 10 President #36: Johnson President #37: Nixon President #38: Ford President #39: Carter President #40: Reagan President #41: George Bush President #42: Clinton President #43: George W Bush President #44: Obama President #45: Trump
Presidents Quiz
Who was president #36? Johnson Who was president #37? Nixon Who was president #40? Carter Who was president #41? George W Bush Who was president #44? Obama
Your score was 3
Here are the last 10 presidents in alphabetical order: Carter Clinton Ford George Bush George W Bush Johnson Nixon Obama Reagan Trump
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