English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Part B
Write a program, called Kg, that converts the following integer values 5, 40, 85 and 120 kilograms to pounds (1 lb = .454kg) and displays the result to the monitor. Create 4 integer variables to hold the 4 kg values. Similarly, you can create 4 double variables to hold the 4 lb values.

Sample output:

5 kg = 11.01 lb
40 kg = 88.10 lb
85 kg = 187.22 lb
120 kg = 264.31 lb

2007-03-02 00:23:06 · 1 answers · asked by LULU 1 in Computers & Internet Programming & Design

1 answers

public class Kg
{
private int val1 = 0;
private int val2 = 0;
private int val3 = 0;
private int val4 = 0;

private double result1 = 0.00;
private double result2 = 0.00;
private double result3 = 0.00;
private double result4 = 0.00;

public Kg()
{

val1 = 5;
val2 = 40;
val3 = 85;
val4 = 140;

result1 = 0.00;
result2 = 0.00;
result3 = 0.00;
result4 = 0.00;

}


public static void main(String[] args)
{

Kg myClass = new Kg();
myClass.result1 = myClass.val1/0.454;
myClass.result2 = myClass.val2/0.454;
myClass.result3 = myClass.val3/0.454;
myClass.result4 = myClass.val4/0.454;
System.out.println( myClass.val1 + " = " + myClass.result1 );
System.out.println( myClass.val2 + " = " + myClass.result2 );
System.out.println( myClass.val3 + " = " + myClass.result3 );
System.out.println( myClass.val4 + " = " + myClass.result4 );

}


}

This is the basic idea. Many improvements can be made at this program. But I let this to you so you can earn a few extra points with your teacher.

2007-03-02 12:53:52 · answer #1 · answered by Anonymous · 0 0

fedest.com, questions and answers