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
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