Overloaded Constructors a) Implement a Weight class with a two-parameter setWeight method that initializes weight and units
Question:
Overloaded Constructors
a) Implement a Weight class with a two-parameter setWeight method that initializes weight and units variables and a one-parameter setWeight method that uses a default “kg” for units. Provide corresponding two- parameter and one-parameter constructors and a print method, which displays weight and units values. Minimize the total number of statements by having the one-parameter constructor call the one- parameter setWeight method and the two-parameter constructor call the two-parameter setWeight method.
b) Provide a main method for a WeightDriver class such that the new main method uses one of the new constructors from part a) to generate this output:
120 lbs
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean