Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Truly need help with part 2! The first programming project involves writing a program that computes the minimum, the maximum and the average weight of

Truly need help with part 2!

The first programming project involves writing a program that computes the minimum, the maximum and the average weight of a collection of weights represented in pounds and ounces that are read from an input file. This program consists of two classes. The first class is the Weight class, which is specified in integer pounds and ounces stored as a double precision floating point number. It should have five public methods and two private methods:

1. A public constructor that allows the pounds and ounces to be initialized to the values supplied as parameters.

2. A public instance method named lessThan that accepts one weight as a parameter and returns whether the weight object on which it is invoked is less than the weight supplied as a parameter.

3. A public instance method named addTo that accepts one weight as a parameter and adds the weight supplied as a parameter to the weight object on which it is invoked. It should normalize the result.

4. A public instance method named divide that accepts an integer divisor as a parameter. It should divide the weight object on which the method is invoked by the supplied divisor and normalize the result.

5. A public instance toString method that returns a string that looks as follows: x lbs y oz, where x is the number of pounds and y the number of ounces. The number of ounces should be displayed with three places to the right of the decimal

. 6. A private instance method toOunces that returns the total number of ounces in the weight object on which is was invoke d.

7. A private instance method normalize that normalizes the weight on which it was invoked by ensuring that the number of ounces is less than the number of ounces in a pound.

PART 2

Both instance variable must be private. In addition the class should contain a private named constant that defines the number of ounces in a pound, which is 16. The must not contain any other public methods.

The second class should be named Project1. It should consist of the following four class (static) methods.

1. The main method that reads in the file of weights and stores them in an array of type Weight. It should then display the smallest, largest and average weight by calling the remaining three methods. The user should be able to select the input file from the default directory by using the JFileChooser class. The input file should contain one weight per line. If the number of weights in the file exceeds 25, an error message should be displayed and the program should terminate.

2. A private class method named findMinimum that accepts the array of weights as a parameter together with the number of valid weights it contains. It should return the smallest weight in that array.

3. A private class method named findMaximum that accepts the array of weights as a parameter together with the number of valid weights it contains. It should return the largest weight in that array.

4. A private class method named findAverage that accepts the array of weights as a parameter together with the number of valid weights it contains. It should return the average of all the weights in that array.

File cant be uploaded but here is the list Year, Weight (lbs) Weight Loss (lbs)

Year, Weight (lbs) Weight Loss (lbs)

1990 500 50

1991 485 15

1992 475 10

1993 450 15

1994 452 0

1995 430 22

1996 428 2

1997 416 12

1998 410 6

1999 408 2

2000 405 3

2001 409 4

2002 402 7

2003 388 14

2004 376 12

2005 366 10

2006 368 2

2007 363 5

2008 342 21

2009 333 9

2010 324 9

2011 310 14

2012 285 25

2013 271 14

2014 265 6

2015 248 17

2016 225 23

2017 210 15

2018 195 15

2019 185 10

2020 171 14

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

More Books

Students also viewed these Databases questions