Program 6

Writing classes using instance variables. Practice with composition.

Due: Thursday, April 9, by noon

You are to write a program that models a simplified natural gas utility company. You will write the following classes.

GasMeter

class constant

a double that holds the RATE per unit of gas – value of 0.055

instance variables

an integer that holds the current meter reading

an integer that holds the prior meter reading

methods

a default constructor

a method that calculates the cost of gas for the current time period as follows:

oresidential customers pay the RATE per unit

obusiness customers pay 80% of the RATE per unit

oall customers receive a 10% discount if they use over 5000 units

Assumption: You may assume that the current meter reading will always be greater than the prior meter reading.

a method that records the meter reading, correctly setting the prior and current values

getters for current reading and prior reading

Customer

instance variables

aGasMeter

a String to hold the customer’s first name

a String to hold the customer’s last name

a char to hold the customer type, R for residential, B for business

methods

a constructor that takes the customer’s first and last names as Strings, and a char that is the customer type

a constructor that takes the customer’s first and last names as Strings

override the Object class equals method. Two customers are equal if their first names are the same and their last names are the same

a method that records a meter reading that takes an integer current reading

a print method that prints out the customer’s first and last name, tells whether or not the customer is a residential customer or a business customer, prints out the current and prior readings and amount used with labels, and prints out the total cost formatted with a $ and two decimal places.

a method that calls the calculate cost method of the GasMeter class, providing the customer type

GasCompany

You should consider writing several helper methods to reuse code that otherwise would be included in several methods. Also use helper methods to make methods more readable.

instance variables

three Customer objects

methods

a default constructor

AnaddCustomer method that accepts a Customer and stores it in one of the instance variables. This method should return true if the Customer was successfully added and false if there was no room for the Customer.

adeleteCustomer method that accepts a Customer and deletes that Customer. If the Customer is found and deleted, return true. Otherwise, return false.

arecordReading method that accepts a Customer and an integer newReading

aprintCustomerBill method that accepts a Customer. See the sample run for expected output.

aprintReport method. See sample run for expected output.

GasCoApp

On my website you will the TextMenu class, which must not be changed in any way. Read it over to understand how it works. You will also find the GasCoApp class, which has been partially written for you. The run() method is complete and must not be changed. There are method stubs for you to complete. You should consider writing several helper methods to reuse code that otherwise would be included in several methods. Also use helper methods to make methods more readable.

This class will have one instance variable, a GasCompany object.

This class will have a main method that instantiates a GasCoApp object and calls the run method. It should do nothing else.

Your program should handle the possibility that the user will enter a name of a person who is in fact not a customer. Your program should not crash and should gracefully explain the problem to the user and prompt the user for a customer name.

This class will do ALL user interaction. No other class should interact with the user.

You are required to validate the customer type input. In other words, if a user enters something other than R, r, B, or b, you must prompt the user for a correct entry.

MISC

You can find a sample run of the program on my website in the Program 6 folder. A run of your program, using the same inputs, should result in identical output.

Create a class diagram showing all files in the program with their proper relationships.

Zip all .java files plus your class diagram into prog6.zip and web submit to your lecture section, project 6.

Extra credit:You may upgrade your program to use a more realistic version of a gas meter. Assume the gas meter has 6 digits. Once the meter reaches 999999, the next value will be 000000. Rework the GasMeter class. You may assume no customer would use more than 999999 units of gas in a time period.Worth 5 extra credit points.

Grading Standards

A perfect program will:

Run correctly, meeting all specifications from the assignment

Code will be

correctly formatted with clear indentation

well commented, following the coding guidelines for this class

be well-designed (including appropriate private helper methods)

submitted correctly, both electronically and on paper

(in a pocket folder, with grade sheet and all required materials, etc.)

An ‘A’ program:

Will run perfectly on the sample run data provided

Will run correctly, meeting all specifications from the assignment

May have no more than two minor errors in commenting and/or submission

Will be well-designed (including appropriate private helper methods)

A ‘B’ program:

Will run correctly, with at most one small deviation from the assignment

Will be well-designed (including appropriate private helper methods)

A ‘C’ program:

Will compile and run

May have multiple minor errors

or errors in multiple areas

or up to 2 major errors

A ‘D’ program

Will compile and run

Has serious errors in execution

An ‘F’ program

Does not compile

or does not run

or substantially fails to follow the assignment guidelines

or has a number of errors of different kinds