Create a measurement converter project that can convert between grams, ounces, p
ID: 3796199 • Letter: C
Question
Create a measurement converter project that can convert between grams, ounces, pounds
and kilograms. Be sure to include the driver class.
The constants for conversion are:
1 ounce = 28.35 grams
16 ounces = 1 pound
1 kg = 1000 grams
Write a class definition file named WeightConverter that has these fields:
weightInOunces
weightInPounds
weightInGrams
weightInKiloGrams
The class also needs the three constant fields for the conversions as listed above.
Write the following methods:
Two constructor methods:
The default constructor sets all the field values to zero except the constant. The constant
is set using the conversion given above.
The overloaded constructor accepts a value for the weight of an item in pounds and
calculates the values for the remaining three fields.
Write four set( ) methods that allows the user to change any measure (setOunces,
setPounds, setGrams, setKiloGrams) The set methods must ensure all the fields are
consistent.
Write four get( ) methods. One get method for each of the four fields (not including the
constants.
Write a driver class that has the main( ) method. This main method should provide the
following utility:
Create an instance of the WeightConverter class using the default values.
Write a loop that allows the user to reset any of the measures. Ask the user to enter which
measure to change, read in the value and call the appropriate set method. Then print the
value of each of the four fields. This process continues until the user indicates he/she
wants to quit.
Once the loop exits, print a Goodbye message.
Explanation / Answer
WeightConverter :
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
driver class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.