Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 02 A Long, Heavy Program Objective: Create a program which prompts the user

ID: 3877874 • Letter: L

Question

Lab 02 A Long, Heavy Program Objective: Create a program which prompts the user to enter a weight assumed in pounds, a height assumed in feet, and then it converts both into several different measures. . The different weight measures from pounds are: o Kilogram-0.456 o Stone 0.071 o Slug 0.031 o Pennyweight 291.667 o Grain-7,000 . The different height measures from feet are o Meter- 0.305 o Hand - 3 o Furlong-0.002 Cubit-0.667 o Rack Unit-6.857 Example Dialog Welcome to the weight and height converter 9000! Enter a weight in pounds Enter a height in feet 1.01bs is 0.456 kilograms 1.01bs is 0.071 stones 1.01bs is 0.031 slugs 1.01bs is 291.667 pennyweights 1.01bs is 7000.0 grains 1.0feet is 0.305 meters 1.0feet is 3.0 hands 1.0feet is 0.002 furlongs 1.0feet is 0.667 cubits 1.0feet is 6.857 rack units Goodbye!

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//UnitConverter.java

import java.util.Scanner;

public class UnitConverter {

      /**

      * Constants for weight measures

      */

      static final double poundInKg = 0.456;

      static final double poundInStone = 0.071;

      static final double poundInSlug = 0.031;

      static final double poundInPennyWeight = 291.667;

      static final double poundInGrain = 7000;

      /**

      * Constants for height measures

      */

      static final double feetInMeter = 0.305;

      static final double feetInHand = 3;

      static final double feetInFurlong = 0.002;

      static final double feetInCubit = 0.667;

      static final double feetInRackUnit = 6.857;

      public static void main(String[] args) {

            /**

            * Scanner object to get user input

            */

            Scanner scanner = new Scanner(System.in);

            try {

                  System.out.println("Welcome to the weight and height converter!");

                  System.out.println("Enter weight in pounds: ");

                  /**

                  * getting the input string, and converting it into double

                  */

                  double pounds = Double.parseDouble(scanner.nextLine());

                  System.out.println("Enter height in feet: ");

                  double feet = Double.parseDouble(scanner.nextLine());

                  /**

                  * Displaying each results, input is rounded to fit maximum of 2

                  * digits after decimal point and outputs are rounded to fit maximum

                  * of 3 digits after the decimal point

                  */

                  System.out.printf("%.2f lbs is %.3f kilograms ", pounds,

                              (pounds * poundInKg));

                  System.out.printf("%.2f lbs is %.3f stones ", pounds,

                              (pounds * poundInStone));

                  System.out.printf("%.2f lbs is %.3f slugs ", pounds,

                              (pounds * poundInSlug));

                  System.out.printf("%.2f lbs is %.3f pennyweights ", pounds,

                              (pounds * poundInPennyWeight));

                  System.out.printf("%.2f lbs is %.3f grains ", pounds,

                              (pounds * poundInGrain));

                  System.out.printf("%.2f feet is %.3f meters ", feet,

                              (feet * feetInMeter));

                  System.out.printf("%.2f feet is %.3f hands ", feet,

                              (feet * feetInHand));

                  System.out.printf("%.2f feet is %.3f furlongs ", feet,

                              (feet * feetInFurlong));

                  System.out.printf("%.2f feet is %.3f cubits ", feet,

                              (feet * feetInCubit));

                  System.out.printf("%.2f feet is %.3f rack units ", feet,

                              (feet * feetInRackUnit));

                  System.out.println("Good Bye!");

            } catch (Exception e) {

                  System.out.println("Invalid input");

            }

      }

}

/*OUTPUT*/

Welcome to the weight and height converter!

Enter weight in pounds:

23

Enter height in feet:

55

23.00 lbs is 10.488 kilograms

23.00 lbs is 1.633 stones

23.00 lbs is 0.713 slugs

23.00 lbs is 6708.341 pennyweights

23.00 lbs is 161000.000 grains

55.00 feet is 16.775 meters

55.00 feet is 165.000 hands

55.00 feet is 0.110 furlongs

55.00 feet is 36.685 cubits

55.00 feet is 377.135 rack units

Good Bye!