Question: JAVA Your goal is to write methods, write conditionals, generate random numbers, and ask the user if the output is correct or incorrect. switchPlanet method

JAVA

Your goal is to write methods, write conditionals, generate random numbers, and ask the user if the output is correct or incorrect.

switchPlanet method

Write a boolean method using a switch that prints a random fact about a planet and returns whether that fact is true or false.

Name this method switchPlanet.

The method should take in a number.

Use a switch to determine which planet fact is selected. You should have 10 planet fact options (5 facts true and 5 false).

Print the random planet fact.

Return whether the fact is true or false.

Main method

Generate a random number between 1 and 10.

Call the switchPlanet method with your randomly generated number. This should print the planet fact and return whether the fact is true or false.

Ask the user whether the fact is true or false.

Call the compare method.

Ask the user if they would like to play again? Repeat the game if they choose yes.

compare method

Write a void method that compares the result from the switchPlanet method with the user's answer to determine if the user is correct or incorrect.

Name this method compare.

This method should be void.

Compare the result from the switchPlanet method with the user's answer using a conditional. Be sure to allow for variations in the user's answer (allow true, True, TRUE, etc.).

Print whether they are correct or incorrect.

Example output:

The Earth is the densest planet in the Solar System. True or False? true Correct Play again (yes or no)? no

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!