Soalan1
import javax.swing.*;
public class lab_dip_5_soalan1
{
public static void main(String args[])
{
int num;
String hasilproses;
num=input();
hasilproses=process( num);
output(num,hasilproses);
System.exit(0);
}
public static int input()
{
int no;
no=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter an integer : "));
return no;
}
public static String process(int no)
{
int baki;
String hasil;
baki=no%2;
if(baki==0)
hasil="even";
else
hasil="odd";
return hasil;
}
public static void output(int no,String hasil)
{
JOptionPane.showMessageDialog(null,no+" is an "+hasil+" integer", "Output",JOptionPane.INFORMATION_MESSAGE);
}
}
Soalan2
import javax.swing.*;
public class lab_dip_5_soalan2
{
public static void main(String args[])
{
double weight, height;
String result;
weight=inputWeight();
height=inputHeight();
result=analyze( height, weight);
output( height, weight, result);
System.exit(0);
}
public static double inputWeight()
{
double weight;
weight=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter weight : "));
return weight;
}
public static double inputHeight()
{
double height;
height=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter height : "));
return height;
}
public static String analyze(double height,double weight)
{
double bmi=weight/((height/100)*(height/100));
String result;
if (bmi<=25)
result="Normal";
else if(bmi>25&&bmi<30)
result="Fat";
else
result="Obese";
return result;
}
public static void output(double height,double weight,String result)
{
JOptionPane.showMessageDialog(null,"Weight : "+weight+"\nHeight : "+height+"\n\nFrom my BMI
>> "+result,"Output",JOptionPane.INFORMATION_MESSAGE);
}
}
Tuesday, February 07, 2006
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment