Programming Problem Design a program in java that can perform three different arithmetic operations based on the...

50.1K

Verified Solution

Question

Programming

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!

Answer & Explanation Solved by verified expert
3.7 Ratings (541 Votes)
import javautilimport javautilScannermain classpublic class Lab4 function displays the menuprivate static void displayMenuSystemoutprintlnPlease choose one option from the    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students