0% found this document useful (0 votes)
3 views7 pages

Java Swing Calculator Program

The document presents a Java class that implements a basic calculator with the operations of addition, subtraction, multiplication, and division. The program prompts the user to enter two numbers and select an operation via a menu. It then performs the corresponding calculation and displays the result.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

Java Swing Calculator Program

The document presents a Java class that implements a basic calculator with the operations of addition, subtraction, multiplication, and division. The program prompts the user to enter two numbers and select an operation via a menu. It then performs the corresponding calculation and displays the result.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import [Link].

*;

public class Menu {

public static void main(String[] args)


{
intop=0;
doublen1,n2,s,m,d,r;
do{
op=[Link]([Link]("nCalculator"))
************n
SUMARn
[2] RESTARn
[3] MULTIPLY
[4] DIVIDE
[5] EXIT
Enter an option:

switch(op)
{
case1
n1=[Link]([Link]("Enter
number 1
n2=[Link]([Link]("Enter
number 2
s=n1+n2;
[Link](null,"The sum is:" + s);
break;
case2:
n1=[Link]([Link]("Enter
number 1
n2=[Link]([Link]("Enter
number 2
r = n1 - n2;
[Link](null,"The subtraction is:" + r);
break;
case3:
n1=[Link]([Link]("Enter
number 1
n2=[Link]([Link]("Enter
number 2
m = n1 * n2;
[Link](null,"The multiplication
es:"+m);
break;
case4:
n1=[Link]([Link]("Enter
number 1
n2 = [Link]([Link]("Enter
number 2
d=n1/n2;
[Link](null,"The division is:"+d);
break;

}
}while(op!=5);
}

import [Link].*;

public class Menu {

public static void main(String []args)

int op=0;

double n1
do{

op=[Link]([Link]("nCalculator"+

************n

[1] SUMARn

RESTARn

[3] MULTIPLY

[4] DIVIDE

[5] EXIT

Enter an option:

switch(op)

case 1:

n1 = [Link]([Link]("Enter number 1"));

n2 = [Link]([Link]("Enter number 2"));

s = n1 + n2;

[Link](null, "The sum is:" + s);

break;

case 2:

n1 = [Link]([Link]("Enter number 1"));

n2=[Link]([Link]("Enter number 2"));

r=n1-n2;

[Link](null,"The subtraction is:"+r);

break;

case 3:

n1 = [Link]([Link]("Enter number 1"));


n2 = [Link]([Link]("Enter number 2"));

m = n1 * n2;

[Link](null,"The multiplication is:" + m);

break;

case 4:

n1 = [Link]([Link]("Enter number 1"));

n2 = [Link]([Link]("Enter number 2"));

d = n1 / n2;

[Link](null,"The division is:"+d);

break;

}while(op!=5);

Final program

package calculator;

import [Link].*;

/**

* @author PROFESSOR
*/

public class Calculator {

/**

The command line arguments

*/

public static void main(String[] args) {

int op=0;

double n1, n2, s, m, d, r;

do{

op=[Link]([Link]("nCalculator" +

************n

[1] SUMARn

RESTARn

[3] MULTIPLY

[4] DIVIDE

[5] EXIT

Enter an option:

switch(op)

case 1:

n1=[Link]([Link]("Enter number 1"));

n2 = [Link]([Link]("Enter number 2"));

s = n1 + n2;
[Link](null, "The sum is:" + s);

break;

case 2:

n1 = [Link]([Link]("Enter number 1"));

n2=[Link]([Link]("Enter number 2"));

r = n1 - n2;

[Link](null, "The subtraction is:" + r);

break;

case 3:

n1 = [Link]([Link]("Enter number 1"));

n2=[Link]([Link]("Enter number 2"));

m=n1*n2;

[Link](null,"The multiplication is:"+m);

break;

case 4:

n1=[Link]([Link]("Enter number 1"));

n2 = [Link]([Link]("Enter number 2"));

d = n1 / n2;

[Link](null,"The division is:" + d);

break;

}while(op!=5);

} // TODO code application logic here


}

You might also like