Programming Problem
Design a program in java that can perform three differentarithmetic operations based on the user’s input.
The three operations are
1. Summation of integers from 1 to m
2. Factorial of a given number n (n!)
3. Finding the leftmost digit of a given integer (note: you haveto use int)
This program should prompt the user a menu including fouroptions, ask the user for one option, and perform the correspondingcomputation. This process will repeat until the user chooses“Quitâ€.
Please use this menu in your program: (use a switchstatement)
Please choose one option from the following menu:
1) Calculate the sum of integers from 1 to m
2) Calculate the factorial of a given number
3) Display the leftmost digit of a given number
4) Quit
Sample Output
Below is an example of what your output should roughly look likewhen this lab is completed. Text in RED represents user input.
Please choose one option from the following menu:
1) Calculate the sum of integers from 1 to m
2) Calculate the factorial of a given number
3) Display the leftmost digit of a given number
4) Quit
1
Enter a number:
4
The sum of 1 to 4 is 10
Please choose one option from the following menu:
1) Calculate the sum of integers from 1 to m
2) Calculate the factorial of a given number
3) Display the leftmost digit of a given number
4) Quit
2
Enter a number: 5
The factorial of 5 is 120
Please choose one option from the following menu:
1) Calculate the sum of integers from 1 to m
2) Calculate the factorial of a given number
3) Display the leftmost digit of a given number
4) Quit
3
Enter a number:
987654321
The leftmost digit of 987654321 is 9
Please choose one option from the following menu:
1) Calculate the sum of integers from 1 to m
2) Calculate the factorial of a given number
3) Display the leftmost digit of a given number
4) Quit 4 Bye
PLEASE USE THE FOLLOWING FORMAT
I need it in the format of a do while loop
Due today please help!
public class Lab4 {
public static void main(String[] args) {
// Declare some variables you need
// -->
do {
// Display the menu
displayMenu();
// Ask the user for one option
// -->
switch (?????) {
// Define four cases for different options. Don't forget\"break\".
// -->
}
} while (?????);
}
/**
* Print the menu
*/
private static void displayMenu() {
System.out.println(\"Please choose one option from the followingmenu:\");
System.out.println(\"1) Calculate the sum of integers from 1 tom\");
System.out.println(\"2) Calculate the factorial of a givennumber\");
System.out.println(\"3) Display the leftmost digit of a givennumber\");
System.out.println(\"4) Quit\");
}
}
If you can explain that would beawesome, thank you!