Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Weight Class Weight class should have three private variables, two private methods and four public methods. Variables Hint: How should/can you access these private variables?

Weight Class

Weight class should have three private variables, two private methods and four public methods. Variables Hint: How should/can you access these private variables?

1. A private constant variable called OUNCES_IN_A_POUND that defines the number of ounces in a pound (16).

2. A private variable called pounds with a data type of integer.

3. A private variable called ounces with a data type of double.

Methods

1. A public parameterized constructor, which initializes the private variables. public Weight (int pounds, double ounces){ // implementation }

2. A private instance method called to Ounces with a return type of double. This method has no parameters and should return the total number of ounces. For full credit, reuse this method across other methods when possible.

3. A private instance method called normalize with a return type of void. This method has no parameters and should ensure that the number of ounces is less than the number of ounces in a pound. For full credit, reuse this method across other methods when possible.

4. A public instance method called less than with a return type of boolean. This method should accept a Weight object as a parameter and determine if the object is greater or less than the initialized values. public boolean lessThan (Weight weight){ // implementation }

5. A public instance method called addTo with a return type of void. This method should accept a Weight object as a parameter and add the objects weight values to the initialized values. public void add To (Weight weight){ // implementation }

6. A public instance method called toString with a return type of String. This method has no parameters and should have the following format: x pounds and y ounces where x is the number of pounds and y is the number of ounces. Ounces should be displayed with two decimal places.

Project1: Class Project1 class should have three private methods and one public method.

Methods

1. A private class method named findMinimum with a return type of Weight. This method should accept three Weight objects as parameters and compare each Weight objects weight values to find the minimum. The Weight object with the minimum weight value should be returned and then printed using toString in the following format: The minimum weight is x pounds and y ounces where x is the number of pounds and y the number of ounces. Ounces should be displayed with two decimal places.

2. A private class method named findMaximum with a return type of Weight. This method should accept three Weight objects as parameters and compare each Weight objects weight values to find the maximum. The Weight object with the maximum weight value should be returned and then printed using toString in the following format:

The maximum weight is x pounds and y ounces

where x is the number of pounds and y the number of ounces. Ounces should be displayed with two decimal places.

3. A private class method named findAverage with a return type of Weight. This method should accept three Weight objects as parameters and calculate the average weight value. A new Weight object with the average weight values should be returned and then printed using toString in the following format: The average weight is x pounds and y ounces where x is the number of pounds and y the number of ounces. Ounces should be displayed with two decimal places.

4. A public method named main with a return type of void. This method should exercise the correct functionality of findMinimum, findMaximum and findAverage by creating three Weight objects using the hardcoded values below: Weight weight1 = new Weight(11, 3); Weight weight2 = new Weight(7, 20); // Hint: normalize method should be used to translate into 8 pounds and 4 ounces Weight weight3 = new Weight(14, 6);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Find e z in the form u + iv and |e z | if z equals 2 + 3i

Answered: 1 week ago

Question

=+f. Does it promise a benefit or solve a problem?

Answered: 1 week ago

Question

=+ Why do some seem like a personalized, individual message?

Answered: 1 week ago