Menu

First Programming Project Involves Writing Program Computes Minimum Maximum Average Weight Q43881443

The first programming project involves writing a program thatcomputes the minimum, the maximum and the average weight of acollection of weights represented in pounds and ounces that areread from an input file. This program consists of two classes. Thefirst class is the Weight class, which is specified in integerpounds and ounces stored as a double precision floating pointnumber. It should have five public methods and two privatemethods:

  1. A public constructor that allows the pounds and ounces to beinitialized to the values supplied as parameters.
  2. A public instance method named lessThan that accepts one weightas a parameter and returns whether the weight object on which it isinvoked is less than the weight supplied as a parameter.
  3. A public instance method named addTo that accepts one weight asa parameter and adds the weight supplied as a parameter to theweight object on which it is invoked. It should normalize theresult.
  4. A public instance method named divide that accepts an integerdivisor as a parameter. It should divide the weight object on whichthe method is invoked by the supplied divisor and normalize theresult.
  5. A public instance toString method that returns a string thatlooks as follows: x lbs y oz, where x isthe number of pounds and y the number of ounces. Thenumber of ounces should be displayed with three places to the rightof the decimal.
  6. A private instance method toOunces that returns the totalnumber of ounces in the weight object on which is was invoked.
  7. A private instance method normalize that normalizes the weighton which it was invoked by ensuring that the number of ounces isless than the number of ounces in a pound.

Both instance variable must be private. In addition the classshould contain a private named constant that defines the number ofounces in a pound, which is 16. The must not contain any otherpublic methods.

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

  1. The main method that reads in the file of weights and storesthem in an array of type Weight. It should then display thesmallest, largest and average weight by calling the remaining threemethods. The user should be able to select the input file from thedefault directory by using the JFileChooser class. The input fileshould contain one weight per line. If the number of weights in thefile exceeds 25, an error message should be displayed and theprogram should terminate.
  2. A private class method named findMinimum that accepts the arrayof weights as a parameter together with the number of valid weightsit contains. It should return the smallest weight in thatarray.
  3. A private class method named findMaximum that accepts the arrayof weights as a parameter together with the number of valid weightsit contains. It should return the largest weight in thatarray.
  4. A private class method named findAverage that accepts the arrayof weights as a parameter together with the number of valid weightsit contains. It should return the average of all the weights inthat array.

Be sure to follow good programming style, which means making allinstance variables private, naming all constants and avoiding theduplication of code. Furthermore you must select enough differentinput files to completely test the program.

Java programming

The text file could not be attached but it looks like this:

Year,Weight in Lbs,Weight Loss Rate
1994,713.6,9
1995,684.5,8.2
1996,636.6,7.4
1997,611,6.8
1998,567.6,6.3
1999,523,5.7
2000,506.5,5.5
2001,504.5,5.6
2002,494.4,5.6
2003,475.8,5.7
2004,463.2,5.5
2005,469,5.6
2006,479.3,5.8
2007,471.8,5.7
2008,458.6,5.4
2009,431.9,5
2010,404.5,4.8
2011,387.1,4.7
2012,387.8,4.7
2013,367.9,4.5

please tell me what to do? How to get the problemdone. Please help!

Expert Answer


Answer to The first programming project involves writing a program that computes the minimum, the maximum and the average weight o…

OR