CONSTRACTOR:
public class Weight1 {
double zkg;
double yg;
double akg;
double sg;
Weight1(double z, double y, double a, double s){
zkg=z;
yg=y;
akg=a;
sg=s;
}
MAIN CLASS:
import java.util.Scanner;
public class Weight {
public static void main (String[]args){
Weight1 r1=new Weight1(0.453592, 453.59237, 0.02834952, 28.34952);
Scanner wieghtconverter = new Scanner(System.in);
System.out.println("Coverter \n Select to convert? \n 1 Pound \n 2 Ounce");
double m1=wieghtconverter.nextInt();
if(m1==1){
System.out.println("Enter number in pounds: ");
double pounds=wieghtconverter.nextInt();
double poundskg=pounds*r1.zkg;
double poundsg=pounds*r1.yg;
System.out.println("Kilograms: "+poundskg);
System.out.println("grams: "+poundsg);
}
else{
System.out.println("Enter number in ounce.");
double ounce=wieghtconverter.nextInt();
double ouncekg=ounce*r1.akg;
double ounceg=ounce*r1.sg;
System.out.println("Kilograms: "+ouncekg);
System.out.println("grams: "+ounceg);
}
}
}
No comments:
Post a Comment