Labs
If an exercise below requires using your solution from a previous chapter, copy-paste code from your existing program into a new class. If you did not finish the program from the previous chapter, use the solution found in reference.
- Using your temperature conversion program from the section
IfElse, create a new class namedIfCelsFahrLoop. It will prompt the user to convert temperatures 5 times. (Hint: be careful of where you close yourScanner. This should be one of the last things the program does.)
(Reference: reference/IfCelsFahr.java)
(Solution: IfCelsFahrLoop.java)
- Write a program that presents a numeric menu to a user. The menu should present five options:
1. Greeting 2. Advice 3. Wisdom 4. Help 5. Quit
Users can select options until they decide to quit the program.
* 1 prints a greeting to the screen.
* 2 prints advice on Java or any other topic.
* 3 prints wisdom, perhaps an old saying.
* 4 explains how the program works, such as "Select an option, enter 5 to quit."
* 5 prints a farewell message and the program ends.
Design this class to have several methods, such as printMenu() and printGreeting().
(Solution: LoopMenu.java)
- Modify the calculator app from the
Switchsection. Use abooleanvariable and ado-whileloop to allow the user to keep entering numbers and operations until they enterQUITorEXITas the operation.
(Reference: reference/CalculatorSwitch.java)
(Solution: CalculatorLoop.java)