Write a Java program that conforms to the following specifications1. The program consists of a single class called Loops2. Loops has a main method3. Loops has the following static methodsa. calculateSum – the input to this method is an integer. The methods returnsthe sum 1+2+3+…+n. Use a for loop to calculate the sumb. calculateProduct – the input to this method is an integer. The methodreturns 1*2*3*…*n. Use a while loop to calculate the product.c. calculatePower – the input to this method is a double value, say x, and aninteger value – say n. The method calculates and returns xy. Use a for loop to dothe calculation.d. menu – this method requires no input parameters. It provides the user thefollowing choices: 1. Calculate sum 1+2+3+42. Calculate product 1*2*3*…*n3. CalculateXToYPower4. QUITThe method returns the user’s selection. 4. In the main method, you should implement the following:main(){ display menu and get user’s choice (1,2,3,4) LOOP (Use a while or do-while) if the choice is 1 ask the user to enter an integer – say n, then read the input from the user call calculateSum to get sum 1+2+3+…+n print n and the sum if the choice is 2 ask the user to enter an integer – say n, then read the input from the user call calculateProduct to get the product 1*2*3*…*n print n and the product if the choice is 3 ask the user to enter a double, say x, then read the input ask the user to enter an integer – say n, then read the input call calculatePower to get xn print the answer  if the choice is 4, terminate the program (You can say System.exit(0); display menu again and get new choiceEND LOOP 5. Here is an outline of the entire programpublic class Loops{ public static int calculateSum(int n) { // put code here } public static double calculateProduct(int n) { //  put code here } public static double calculateXToYPower(int n, double x) { //put code here } public static int menu() { //put code here}public static void main(String[] args){ int choice = menu(); while(choice !=4) { if (choice == 1)…… else if(choice == 2) ….etcetera… choice = menu();  }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a Java program that conforms to the following specifications
1. The program consists of a single class called Loops
2. Loops has a main method
3. Loops has the following static methods
a. calculateSum – the input to this method is an integer. The methods returns
the sum 1+2+3+…+n. Use a for loop to calculate the sum
b. calculateProduct – the input to this method is an integer. The method
returns 1*2*3*…*n. Use a while loop to calculate the product.
c. calculatePower – the input to this method is a double value, say x, and an
integer value – say n. The method calculates and returns xy
. Use a for loop to do
the calculation.
d. menu – this method requires no input parameters. It provides the user the
following choices: 
1. Calculate sum 1+2+3+4
2. Calculate product 1*2*3*…*n
3. CalculateXToYPower
4. QUIT
The method returns the user’s selection.

4. In the main method, you should implement the following:
main()
{
 display menu and get user’s choice (1,2,3,4)
 LOOP (Use a while or do-while)
 if the choice is 1
 ask the user to enter an integer – say n, then read the input from the user
 call calculateSum to get sum 1+2+3+…+n
 print n and the sum
 if the choice is 2
 ask the user to enter an integer – say n, then read the input from the user
 call calculateProduct to get the product 1*2*3*…*n
 print n and the product
 if the choice is 3
 ask the user to enter a double, say x, then read the input
 ask the user to enter an integer – say n, then read the input
 call calculatePower to get xn

print the answer

 if the choice is 4, terminate the program (You can say System.exit(0);
 display menu again and get new choice
END LOOP

5. Here is an outline of the entire program
public class Loops
{
 public static int calculateSum(int n)
 {
 // put code here
 }
 public static double calculateProduct(int n)
 {
 //  put code here
 }
 public static double calculateXToYPower(int n, double x)
 {
 //put code here
 }
 public static int menu()
 {
 //put code here
}
public static void main(String[] args)
{
 int choice = menu();
 while(choice !=4)
 {
 if (choice == 1)……
 else if(choice == 2) ….
etcetera…
 choice = menu();

 } 

AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education