02-13-2010, 09:41 AM
|
#1 (permalink)
|
|
Moderator
Join Date: Sep 2009
Posts: 303
Thanks: 0
Thanked 89 Times in 61 Posts
|
my java program
this is my first work in java programming its kinda noob. nyahha
Quote:
import javax.swing.*;
public class Aricthmetic{
public void choose_Operator (int Opt){
switch (Opt){
case 1:
JOptionPane.showMessageDialog(null, "you choose 1 which is the addition press ok to continue");
int add1,add2,sum;
add1=Integer.parseInt(JOptionPane.showInputDialog( "input number to be added:"));
add2=Integer.parseInt(JOptionPane.showInputDialog( "input number to be added:"));
sum=add1+add2;
JOptionPane.showMessageDialog(null,sum+" is the sum");
break;
case 2:
JOptionPane.showMessageDialog(null, "you choose 2 which is the subtration press ok to continue");
int sub1,sub2,subtration;
sub1=Integer.parseInt(JOptionPane.showInputDialog( "input number to be subtrated:"));
sub2=Integer.parseInt(JOptionPane.showInputDialog( "input number to be subtrated:"));
subtration=sub1-sub2;
JOptionPane.showMessageDialog(null,subtration+" is the different");
break;
case 3:
JOptionPane.showMessageDialog(null, "you choose 3 which is the multiplication press ok to continue");
int mul1,mul2,Multiplication;
mul1=Integer.parseInt(JOptionPane.showInputDialog( "input number to be multiple:"));
mul2=Integer.parseInt(JOptionPane.showInputDialog( "input number to be multiple:"));
Multiplication=mul1*mul2;
JOptionPane.showMessageDialog(null,Multiplication+ " is the product");
break;
case 4:
JOptionPane.showMessageDialog(null, "you choose 4 which is the division press ok to continue");
int div1,div2,divide;
div1=Integer.parseInt(JOptionPane.showInputDialog( "input number to be divided:"));
div2=Integer.parseInt(JOptionPane.showInputDialog( "input number to be divided:"));
if (div2==0){JOptionPane.showMessageDialog(null , "you cant input zero value");
}
else{
divide=div1/div2;
JOptionPane.showMessageDialog(null,divide+" is the quotient");
break;
}
default:
JOptionPane.showMessageDialog(null,"you choose nothing press ok to exit");
}
}
public static void main(String args[]){
Aricthmetic obj = new Aricthmetic();
boolean continuex=true;
while (continuex){
int x = Integer.parseInt(JOptionPane.showInputDialog("ninz calculator version 1.0.4\n \n1.ADDITION\n 2.SUBTRACTION\n 3.MULTIPLICATION\n 4.DIVISION\n CHOOSE OPERATOR:"));
obj.choose_Operator(x);
int cont= JOptionPane.showConfirmDialog(null,"do you to have another transaction?");
if (cont!=0){
continuex=false;
}
}
}
}
|
__________________
|
|
|