Beruflich Dokumente
Kultur Dokumente
// getters
public String getAdd()
{
return add;
}
}
//the main code for the calculator and menu
/*group 3:
december 16 2008
11 pm
*/
import javax.swing.JOptionPane;
public class Calculator{
//THE CHOICES:
if (choice==1)
{
int basic=Integer.parseInt (JOptionPane.showInputDialog ("do you want to: \n 1. add
\n 2. subtract \n 3. multiply \n 4. divide"));
//THE CHOICES UNDER THE BASIC CALCULATOR
switch (basic)
{
case 1:
String add=JOptionPane.showInputDialog ("enter first number");
String add2=JOptionPane.showInputDialog ("enter second number");
float anum1=Float.parseFloat(add);
float anum2=Float.parseFloat(add2);
float sum=anum1+anum2;
JOptionPane.showMessageDialog (null, "the sum is "+sum);
break;
case 2:
String sub=JOptionPane.showInputDialog ("enter first number");
String sub2=JOptionPane.showInputDialog ("enter second number");
float snum1=Float.parseFloat(sub);
float snum2=Float.parseFloat(sub2);
float dif=snum1-snum2;
JOptionPane.showMessageDialog (null, "the difference is "+dif);
break;
case 3:
String mult=JOptionPane.showInputDialog ("enter first number");
String mult2=JOptionPane.showInputDialog ("enter second number");
float mnum1=Float.parseFloat(mult);
float mnum2=Float.parseFloat(mult2);
float prod=mnum1*mnum2;
JOptionPane.showMessageDialog (null, "the product is "+prod);
break;
case 4:
String div=JOptionPane.showInputDialog ("enter first number");
String div2=JOptionPane.showInputDialog ("enter second number");
float dnum1=Float.parseFloat(div);
float dnum2=Float.parseFloat(div2);
float quo=dnum1/dnum2;
JOptionPane.showMessageDialog (null, "the quotient is "+quo);
break;
}
}
else if (choice==2)
{
int science=Integer.parseInt (JOptionPane.showInputDialog ("choose a funtion \n 1.
sine \n 2. cosine \n 3. tangent"));
else if (choice==3)
{
JOptionPane.showMessageDialog (null, "bye!!!");
System.exit(0);
}
else {
JOptionPane.showMessageDialog (null, "unknown command");
}
}
}
}