Answered step by step
Verified Expert Solution
Question
1 Approved Answer
create a Java program that implements a menu system using only conditional statements and Loogs. The program should provide the user with a menu
create a Java program that implements a menu system using only conditional statements and Loogs. The program should provide the user with a menu of options, allow them to choose an option, and then perform the corresponding action based on their choice. The nenu should keep looping until the user chooses to exit. For this lab, you are not allowed to create methods for the different tanka. Menu Options: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Functionality of Menu Options: 1. Calculate Factorial: - Prompt the user to enter a positive integer. - Continue asking for input if the user inputs a negative number. - Calculate and display the factoria of the entered number. - Return to the main menu after displaying the result. 2. Check Prime Number: - Prompt the user to enter a positive integer greater than 1. - Continue asking for input unti: a valid positive integer greater than 1 is provided. - Determine if the entered number is prine or not. - Display whether the number is prime or not.. - Return to the main menu after displaying the result. 3. Find the Sum of Digits: - Prompt the user to enter a positive integer with at least two digits. - Continue asking for input unti: a valid positive integer with at least two digits is provided. - Calculate and display the sum of the digits of the entered number. - Return to the main menu after displaying the result. 4. Reverse a Number: - Prompt the user to enter a positive integer with at least two digits. - Continue asking for input unti: a valid positive integer with at least two digits is provided. - Reverse the digits of the entered number and display the result. - Return to the main menu after displaying the result. 5. Exit: - Exit the program. Additional Requirements: - Handle invalid inputs gracefully (i.e., negative numbers, less than two digits) and display appropriate error messages. - Ensure that the program continues running until the user chooses to exit. - Use only conditional statements for menu option selection. - Use loops to control the flow of the program. - Do not create methods or functions for this assignment. - You can use methods from the Scanner and Math classes. Examples of its use: Invalid option Menu: 1. Calculate Factorial. 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: 9 Invalid choice. Please enter a valid option. Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: Option 1 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number: 5. Exit Enter your choice: 1 Enter a positive integer: -5 Enter a positive integer: 5 Factorial of 5 is: 120 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: Option 2 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: 2 Enter a positive integer: -8 Enter a positive integer: 175 175 is not a prime number. Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: Option 3 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number. 5. Exit Enter your choice: 31 Enter a positive integer with at least two digits: 5 Enter a positive integer with at least two digits: -125 Enter a positive integer with at least two digits: 125 Sum of digits is: 8 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: Option 4 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: 41 Enter a positive integer with at least two digits: 6 Enter a positive integer with at least two digits: -2545 Enter a positive integer with at least two digits: 2545 Reversed number is: 5452 Menu: 1. Calculate Factorial 2. Check Prime Number 3. Find the Sum of Digits 4. Reverse a Number 5. Exit Enter your choice: Option 5 Menu: 1. Calculate Factorial. 2. Check Prime Number 3. Find the Sum of Digita 4. Reverse a Humber 5. Exit Enter your choice: 5 Exiting the program. Goodbye! If your program terminates after each options, then it is not correct!
Step by Step Solution
★★★★★
3.44 Rating (144 Votes )
There are 3 Steps involved in it
Step: 1
Heres a Java program that implements the menu system with conditional statements and loops based on ...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