All pastes #515139 Raw Edit

Anonymous

public text v1 · immutable
#515139 ·published 2007-05-28 02:07 UTC
rendered paste body
/*
 * MassHeightConverter.java
 *
 * Created on May 24, 2007, 6:02 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package bmicalculator;
import java.util.Scanner;
/**
 *
 * @author crusoe
 */
public class MassHeightConverter {
    
    /** Creates a new instance of MassHeightConverter */
    public MassHeightConverter() {
    }
    
    public static void main(String[] args) {
        Double mass;
        String massUnitType;
        Double height;
        String heightUnitType;
        
        
        
        System.out.println("Enter mass value?");
        mass = new Double(new Scanner(System.in).nextLine());
        
        System.out.println("Enter unit of the mass value? (lb, kg)");
        massUnitType = new String(new Scanner(System.in).nextLine());
        
        System.out.println("Enter height value?");
        height = new Double(new Scanner(System.in).nextLine());
        
        System.out.println("Enter unit of the height value (feet, yards, meters)?");
        heightUnitType = new String(new Scanner(System.in).nextLine());
        
        
        if (massUnitType.equalsIgnoreCase("lb") ) {
            System.out.printf("The mass of %4.2f lb equals %4.2f kg\n", mass, (mass*0.4535924));
        } else if (massUnitType.equalsIgnoreCase("kg") ) {
            System.out.printf("The mass of %4.2f kg equals %4.2f lb\n", mass, (mass/0.4535924));
        } else{
            System.out.printf("You entered wrong mass units %s\n", massUnitType);
        }
        
        if (heightUnitType.equalsIgnoreCase("feet") ) {
            System.out.printf("The height equals %4.2f meters\n", (height*0.3048));
        } else if (heightUnitType.equalsIgnoreCase("yards") ) {
            System.out.printf("The height equals %4.2f meters\n", (height*0.9144));
        } else if (heightUnitType.equalsIgnoreCase("meters") ) {
            System.out.printf("The height equals %4.2f meters\n", height);
        }else{
            System.out.printf("You entered wrong height units %s\n", heightUnitType);
        }
    }
}