Writing a program that computes the minimum weight

Assignment Help Programming Languages
Reference no: EM132649939

CMIS242 Intermediate Programming - University of Maryland Global Campus

Programming Project 1

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 a data file. This program consists of twoparts. The first part is the Weight class and the second part is the Program Core.

The Weight Class is specified in integer pounds and ounces stored as a double precision floating point number, that is, a percentage of a pound. It should have five public methods and two private methods:

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

2. A public instancemethod 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 addsthe 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 instancetoString 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 four 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 invoked. Two processes occur in this method. The first process takes the value read in from a data file that is a percentage of a pound and it is checked that is one of fifteen acceptable numbers using modulo of integer division (See the Conversion Table). If the value is not an acceptable number, then a message is displayed indicating that the value is not acceptable. That value is not included in the array used to determine the average. If the value is acceptable, the percentage of a pound is converted into one of the fifteen ounces with integer division. That value is returned.

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.

Both instance variables 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 class must not contain any other public methods.

The second partis the Program Core. 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 data file from a default directory by using the JFileChooser class. Reading the data can follow the coding used in ReadEmails.java found in Week 2 |Code Examples. Attached to this assignment are two files containing weights: PRJ1WeightsLess and PRJ1WeightsMore. The second file contains more than 25 entries. The data file contains one weight per line divided into two parts: the pound as integer and the percentage of a pound as a float. If the number of weights in the file exceeds 25, an error message should display, and the program should terminate with a message.

2. A private class method namedfindMinimum 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.

Be sure to follow good programming style, which means making all instance variables private, naming all constants and avoiding the duplication of code. Furthermore, you must select enough different data filesfor testing and enough weights to completely test the program.

Reference no: EM132649939

Questions Cloud

Procedures and processes for risk management : List and describe three (3) typical organisational policies, procedures and processes for risk management.
Write a policy about flexible hours for company : Make up a hypothetical company or use one that you are familiar with.
Describe the focus of restorative justice : Restorative justice has emerged as a different way for communities to respond to the harm caused by crime. Describe the focus of restorative justice.
How to compute the manufacturing cycle efficiency : How to Compute the manufacturing cycle efficiency. Electron Inc. produces a variety of electronic products which it sells to retail stores
Writing a program that computes the minimum weight : 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
Find company overall commitment to employees : It is helpful to think of your company's overall commitment to employees and their families' needs.
Prepare company income statement for year for jade company : Using the absorption costing method, prepare the company's income statement for the year. Using variable costing method, prepare the company's income statement.
How the problems are perceived by the public : Do you think the media plays a role (whether positive or negative) in how these problems are perceived by the public? Be specific, and do not speak just.
Planned corporate level strategy of merafe resources : Outline the planned corporate level strategy of Merafe Resources. Use examples from the case to justify your strategy selection. What strategy do they use and w

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd