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.

  1. Using your temperature conversion program from the section IfElse, create a new class named IfCelsFahrLoop. It will prompt the user to convert temperatures 5 times. (Hint: be careful of where you close your Scanner. This should be one of the last things the program does.)

(Reference: reference/IfCelsFahr.java)

(Solution: IfCelsFahrLoop.java)

  1. 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)

  1. Modify the calculator app from the Switch section. Use a boolean variable and a do-while loop to allow the user to keep entering numbers and operations until they enter QUIT or EXIT as the operation.

(Reference: reference/CalculatorSwitch.java)

(Solution: CalculatorLoop.java)


Prev -- Up