Methods:
public class metod {
public static String computation1 {
JOptionPane.showMessageDialog(null," Area of a Circle");
String n = JOptionPane.showInputDialog(null,"Enter a Number");
int num = Integer.parseInt(n);
int form1 = (3.14 * (num*2));
JOptionPane.showMessageDialog(null,"… is "+form1);
}
public static String computation2 {
JOptionPane.showMessageDialog(null,"… of a Trapezoid");
String h = JOptionPane.showInputDialog(null,"Enter Height");
int heig = Integer.parseInt(h);
String b1 = JOptionPane.showInputDialog(null,"Enter Base1");
int bas = Integer.parseInt(b1);
String b2 = JOptionPane.showInputDialog(null,"Enter Base2");
int base = Integer.parseInt(b2);
int form2 = (heig * (bas+base) / 2);
JOptionPane.showMessageDialog(null,"… is "+form2);
}
public static String computation3 {
JOptionPane.showMessageDialog(null,"… of a Sphere");
String r = JOptionPane.showInputDialog(null,"Enter Radius");
int rad = Integer.parseInt(r);
int form3 = (.75 * 3.14 *(rad*2));
JOptionPane.showMessageDialog(null,"… is "+form3);
}
public static String computation4 {
JOptionPane.showMessageDialog(null,"… of a Cylinder");
String r2 = JOptionPane.showInputDialog(null,"Enter Radius");
int radiu = Integer.parseInt(r2);
String h2 = JOptionPane.showInputDialog(null,"Enter Height");
int heigh = Integer.parseInt(h2);
int form4 = (3.14 * (radiu * 2) + heigh);
JOptionPane.showMessageDialog(null,"… is "+form4);
}
}
Main:
import javax.swing.JOptionPane;
public class main {
public static void main (String[]srgs){
JOptionPane.showMessageDialog(null,"1… of a Circle\n" + "2.Area of a Trapezoid\n" + "3.Volume of a Sphere\n" + "4.Volume of a Cylinder");
String ipt = JOptionPane.showInputDialog(null,"Input your desired choice(1,2,3,4)");
Integer iptipt = Integer.parseInt(ipt);
switch (iptipt)
{
case 1 :
{
JOptionPane.showMessageDialog(null,"\n" + computation1.getcomputation1); break;
}
case 2 :
{
JOptionPane.showMessageDialog(null,"\n" + computation2.getcomputation2); break;
}
case 3 :
{
JOptionPane.showMessageDialog(null,"\n" + computation3.getcomputation3); break;
}
case 4 :
{
JOptionPane.showMessageDialog(null,"\n" + computation4.getcomputation4); break;
}
default :
{
JOptionPane.showMessageDialog(null,"Unknown");
}
}
}
}
this is wrong completely... i just want to know how would i make this work.. this is on method and switch case staments....(java language)