Exercise 1: A Basic Java Program

Create a file named Weight.java, in the directory exercises/ex1 in your repository. In this file, create a class named Weight, containing a program that converts a weight in kilograms into the equivalent weight in old-fashioned Imperial units of pounds and ounces.

Your program should allow the weight in kilograms to be input by the user as a floating-point value, and it should represent this value internally using the double type. It should convert this value into numbers of pounds and ounces, using an int variable to represent the number of pounds and a double variable to represent the number of ounces. The program should display the converted weight in a single line of output. The number of ounces should be displayed with 1 decimal place of accuracy.

Here is an example of what the user should see when running the program from a terminal window:

$ java Weight
Enter weight in kilograms: 1.8
Equivalent imperial weight is 3 lb 15.5 oz

Note that the output uses the standard abbreviations for pounds and ounces: ’lb’ and ‘oz’.

Go to Submit My WorkExercises 1-5Exercise 1 in Minerva to submit your solution for grading. You can improve your solution and resubmit as many times as you like until the deadline. Also, don’t forget to commit your work to your Git repository and push those commits up to GitLab.

Tips