import javax.swing.JOptionPane;
class homework{
public static void main(string[]args)
{
String ipt,n,h,r,r2,h2,b1,b2;
Double iptipt;
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");
ipt = JOptionPane.showInputDialog(null,"Input your desired choice(1,2,3,4)");
iptipt = Double.parseDouble(ipt);
if (iptipt == 1) ------ IF ELSE STATEMENTS WILL BE IN CASE
{
JOptionPane.showMessageDialog(null," Area of a Circle");}......
n = JOptionPane.showInputDialog(null,"Enter a Number"); } THIS SHOULD BE
int num = Integer.parseInt(n); } IN A METHOD
int form1 = (3.14 * (num*2)); } AND SO AS
JOptionPane.showMessageDialog(null,"… is "+form1); } THE OTHERS
}
else if (iptipt == 2)
{
JOptionPane.showMessageDialog(null,"… of a Trapezoid");
h = JOptionPane.showInputDialog(null,"Enter Height");
int heig = Integer.parseInt(h);
b1 = JOptionPane.showInputDialog(null,"Enter Base1");
int bas = Integer.parseInt(b1);
b2 = JOptionPane.showInputDialog(null,"Enter Base2");
int base = Integer.parseInt(b2);
int form2 = (heig * (bas+base) / 2);
JOptionPane.showMessageDialog(null,"… is "+form2);
}
else if (iptipt == 3)
{
JOptionPane.showMessageDialog(null,"… of a Sphere");
r = JOptionPane.showInputDialog(null,"Enter Radius");
int rad = Integer.parseInt(r);
int form3 = (.75 * 3.14 *(rad*2));
JOptionPane.showMessageDialog(null,"… is "+form3);
}
else
{
JOptionPane.showMessageDialog(null,"… of a Cylinder");
r2 = JOptionPane.showInputDialog(null,"Enter Radius");
int radiu = Integer.parseInt(r2);
h2 = JOptionPane.showInputDialog(null,"Enter Height");
int heigh = Integer.parseInt(h2);
int form4 = (3.14 * (radiu * 2) + heigh);
JOptionPane.showMessageDialog(null,"… is "+form4);
}
}
}
so in the case statement you will just put a code to call for the method where you have put the above codes.. try running this you would understand.. this is from jcreator(java language). instead of putting all of those codes in the if else, just put it in a method.. area of a circle = 1 method, area of a trapezoid = 1 method, volume of a cylinder = 1 method, volume of a sphere = 1 method.. then you will call it in the case statements. which i really don't know how.. i just need a syntax, and a little example too. please help thankyou.. sorry if some statements are redundant.. i just want to make it clear.