Assignment 5
Goal
In this assignment you will program a menu-based calculator and practice using...
• Switch statements
• Loops
Requirements
Your program will perform one of two options repeatedly until the user quits your program.
• Create your program using Eclipse. Name your project Assignment5 and the Java class Loops.
• Use the Scanner class to get input from the user and use System.out to print to the console window.
• Use a while (or a do...while) to have the program loop until the user enter -1
• Inside the while, display a menu similar to the one below and use switch statement to respond to the user's choice
Please enter one of the following choices:
1 --> Largest Number
2 --> Factorial
-1 --> Quit
• For the Largest Number:
o Use ANOTHER while (or a do...while) loop ask the user to input an integer greater than or equal to 0 or -1 to quit.
Input an integer greater than or equal to 0 or -1 to quit:
o When the user enters -1, print out the largest number found
• For the Factorial:
o Ask the user for an integer that we will calculate the factorial.
o In math the factorial is notated as "n!". It is the product of all positive integers less than or equal to n. For example, 5! =5x4x3x2x1= 120. Meanwhile 3! = 3 x 2 x 1 = 6
o Here are the factorial rules
• If the integer is negative, display an error message
• Else if the integer is 0, then 0! = 1 so automatically print 1 as the answer
• Else calculate the factorial with a for loop and display the result.
o When finished, display the result
o Hint: use the factorial result as a long and not an int as the values can get quite large
• Display the result in a readable format.
• Be sure to comment your code.