Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with this Java program The Output Should Be A To review about control

ID: 3744472 • Letter: N

Question

Need help with this Java program

The Output Should Be A To review about control structure and user-define functions in this lab, create the application with the driver class named as ReviewControlStructure.java that provides a menu to allow users to choose either work on integers or decimal numbers to add, minus, multply or dvide two numbers. You should allow users to continue using the program until users want to choose exit How to Install Eclipse D MENU -CALCULATOR ON TWO NUMBERS 1. Add two integers 2. Subtract two integers 3. Multiply two integers 4. Divide two integers 5. Add two decimal numbers 6. Subtract two decimal numbers 7. Multiple two decimal numbers 8. Divide two decimal numbers e. Exit The output should be as below (example) CALCULATOR OF LIEM LE ADD TO INTEGERS 627 -29 CALCULATOR OF LIEM LE SUBTRACT TWO INTEGERS 28 25 183 CALCULATOR OF LIEM LE MULTIPLY TO INTEGERS 2315 345 CALCULATOR OF LZEM LE DIVIDE TO INTEGERS 2475 / 25 #99 CALCULATOR OP LIEM LE 23 456543234-77.5 CALCULATOR OF LIERLE DIVIDE THO DECIMAL MERS 234 1237 12.6-36.5 you have to add the file name as the first comment line Wrirte the comments into your program before each action -Change the name Liem Le in the output to your name You have to create at least 2 user-defined functions that are called in main)

Explanation / Answer

import java.util.Scanner;

class Main

{

//add two integer function

void addinteger(int a,int b)

{

System.out.println("Calculator of RICK");

System.out.println("ADD TWO INTEGERS");

System.out.println(a+" + "+b+" = "+(a+b));

}

//subtract two integer function

void subinteger(int a,int b)

{

System.out.println("Calculator of RICK");

System.out.println("SUBTRACT TWO INTEGERS");

System.out.println(a+" - "+b+" = "+(a-b));

}

//multiply two integer function

void mulinteger(int a,int b)

{

System.out.println("Calculator of RICK");

System.out.println("MULTIPLY TWO INTEGERS");

System.out.println(a+" * "+b+" = "+(a*b));

}

//divide two integer function

void divinteger(int a,int b)

{

System.out.println("Calculator of RICK");

System.out.println("DIVIDE TWO INTEGERS");

System.out.println(a+" / "+b+" = "+(a/b));

}

//add two decimal number function

void adddeci(double a,double b)

{

System.out.println("Calculator of RICK");

System.out.println("ADD TWO DECIMAL NUMBERS");

System.out.println(a+" + "+b+" = "+(a+b));

}

//subtract two decimal number function

void subdeci(double a,double b)

{

System.out.println("Calculator of RICK");

System.out.println("SUBTRACT TWO DECIMAL NUMBERS");

System.out.println(a+" - "+b+" = "+(a-b));

}

//multiply two decimal number function

void muldeci(double a,double b)

{

System.out.println("Calculator of RICK");

System.out.println("MULTIPLICATION TWO DECIMAL NUMBERS");

System.out.println(a+" * "+b+" = "+(a*b));

}

//divide two decimal number function

void divdeci(double a,double b)

{

System.out.println("Calculator of RICK");

System.out.println("DIVIDE TWO DECIMAL NUMBERS");

System.out.println(a+" / "+b+" = "+(a/b));

}

public static void main(String[] args) //main function

{

Scanner sc=new Scanner(System.in);

int ch; //variable decaration

Main obj=new Main(); //object of the class

do

{

//menu for user

System.out.println();

System.out.println("MENU - CALCULATOR ON TWO NUMBERS");

System.out.println("1.Add two integers");

System.out.println("2.Subtract two integers");

System.out.println("3.Multiply two integers");

System.out.println("4.Divide two integers");

System.out.println("5.Add two decimal numbers");

System.out.println("6.Subtract two decimal numbers");

System.out.println("7.Multiply two decimal numbers");

System.out.println("8.Divide two decimal numbers");

System.out.println("0.Exit");

System.out.println("Enter your choice");

ch=sc.nextInt();

switch(ch)

{

case 1:

int n1,n2;

System.out.println("Enter the first number");

n1=sc.nextInt();

System.out.println("Enter the second number");

n2=sc.nextInt();

obj.addinteger(n1,n2);

break;

case 2:

int n3,n4;

System.out.println("Enter the first number");

n3=sc.nextInt();

System.out.println("Enter the second number");

n4=sc.nextInt();

obj.subinteger(n3,n4);

break;

case 3:

int n5,n6;

System.out.println("Enter the first number");

n5=sc.nextInt();

System.out.println("Enter the second number");

n6=sc.nextInt();

obj.mulinteger(n5,n6);

break;

case 4:

int n7,n8;

System.out.println("Enter the first number");

n7=sc.nextInt();

System.out.println("Enter the second number");

n8=sc.nextInt();

obj.divinteger(n7,n8);

break;

case 5:

double a1,a2;

System.out.println("Enter the first number");

a1=sc.nextDouble();

System.out.println("Enter the second number");

a2=sc.nextDouble();

obj.adddeci(a1,a2);

break;

case 6:

double a3,a4;

System.out.println("Enter the first number");

a3=sc.nextDouble();

System.out.println("Enter the second number");

a4=sc.nextDouble();

obj.subdeci(a3,a4);

break;

case 7:

double a5,a6;

System.out.println("Enter the first number");

a5=sc.nextDouble();

System.out.println("Enter the second number");

a6=sc.nextDouble();

obj.muldeci(a5,a6);

break;

case 8:

double a7,a8;

System.out.println("Enter the first number");

a7=sc.nextDouble();

System.out.println("Enter the second number");

a8=sc.nextDouble();

obj.divdeci(a7,a8);

break;

case 0:

System.exit(0);

break;

default:

System.out.println("Invalid Choice");

break;

}

}while(ch!=0);

}

}

OUTPUT

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
1
Enter the first number
10
Enter the second number
20
Calculator of RICK
ADD TWO INTEGERS
10 + 20 = 30

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
2
Enter the first number
40
Enter the second number
30
Calculator of RICK
SUBTRACT TWO INTEGERS
40 - 30 = 10

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
3
Enter the first number
43
Enter the second number
3
Calculator of RICK
MULTIPLY TWO INTEGERS
43 * 3 = 129

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
4
Enter the first number
50
Enter the second number
10
Calculator of RICK
DIVIDE TWO INTEGERS
50 / 10 = 5

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
5
Enter the first number
10.2
Enter the second number
30.5
Calculator of RICK
ADD TWO DECIMAL NUMBERS
10.2 + 30.5 = 40.7

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
6
Enter the first number
58.4
Enter the second number
28.6
Calculator of RICK
SUBTRACT TWO DECIMAL NUMBERS
58.4 - 28.6 = 29.799999999999997

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
7
Enter the first number
34.6
Enter the second number
72.5
Calculator of RICK
MULTIPLICATION TWO DECIMAL NUMBERS
34.6 * 72.5 = 2508.5


MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
8
Enter the first number
22.1
Enter the second number
11.2
Calculator of RICK
DIVIDE TWO DECIMAL NUMBERS
22.1 / 11.2 = 1.973214285714286

MENU - CALCULATOR ON TWO NUMBERS
1.Add two integers
2.Subtract two integers
3.Multiply two integers
4.Divide two integers
5.Add two decimal numbers
6.Subtract two decimal numbers
7.Multiply two decimal numbers
8.Divide two decimal numbers
0.Exit
Enter your choice
0