Lab05
BCIS 5390 Lab 05 Problem Statement
Lab 5 relates to the material covered in Chapter 6 – A First Look at Classes and Objects as well as concepts covered in
previous chapters and lab assignments. In this lab a class will be defined and an object of the class will be created and
utilized. A described in Chapter 6, a class includes members such as fields, constructors, and methods. Lab 5 will consist
of modifying Lab 4 by implementing the following (hint: in many cases the methods in Lab 4 will also be methods of the
class rather than defined in main):
1. Create a Class (with a descriptive name of your choice) which includes the following members:
Private Fields (MUST include private keyword in declaration with appropriate name and data type):
Named constants for each package cost (Note: the static keyword is NOT necessary in the declaration) Named constants for each county discount rate (see note above) Hours worked (appropriate numeric data type) Zip code (only needs to store the first character of the zip code entered by the user) County (String data type) Package Type (character data type)
Constructors:
No‐arg constructor which receives no arguments and initializes each private field (i.e., hours worked, zip code, county, package type) with the appropriate value:
o numeric fields should be assigned a value of 0 o character fields should be assigned a space enclosed in single quotes, ‘ ‘ o string fields should be assigned an empty string which is two double quotes with no space, “”
Parameterized constructor which receives the value of hours worked, zip code, county, and package type as arguments from the main method and assigns to appropriately named parameter variables (i.e., parameters)
which are used to assign a value to each private field
Mutator Methods with appropriate name traditionally beginning with the word set (for assigning a value to each
private field – declared as public):
Receives the value of hours worked as an argument from the main method into an appropriately named parameter and assigns the value to the hours worked private field
Receives the value of zip code (only the first character) as an argument from the main method into an appropriately named parameter and assigns the value to the zip code private field
Receives the value of county as an argument from the main method into an appropriately named parameter and assigns the value to the county private field
Receives the value of package type as an argument from the main method into an appropriately named parameter and assigns the value to the package type private field
Accessor Methods with appropriate name traditionally beginning with the word get (for returning the value of each
private field, calculated values, and displaying output – declared as public):
Receives no arguments and returns the value of the hours worked private field Receives no arguments and returns the value of the zip code private field
Receives no arguments and returns the value of the county private field Receives no arguments and returns the value of the package private field Receives no arguments and returns the value of base charge Receives no arguments and returns the value of additional charge Receives no arguments and returns the value of surcharge Receives no arguments and returns the value of subtotal (hint: think about how the previously created accessor
methods may be used to calculate subtotal which the sum of base charge, additional charge, and surcharge)
Receives no arguments and returns the value of discount rate Receives no arguments and returns the value of discount amount (hint: think about how the previously created
accessor methods may be used to calculate discount amount which is subtotal * discount rate)
Receives no arguments and returns the value of total charge (hint: think about how the previously created accessor methods may be used to calculate total charge which is subtotal – discount amount)
Receives no arguments and prints the savings for Package B and Package C customers 2. In the main method create an appropriately named object of the Class defined above using either the no‐arg
constructor to create the object and calling each of the mutator methods to assign values to the private fields OR
using the parameterized constructor and passing the value of hours worked, zip code (first character only), county,
and package type as arguments. In addition the main method should include the following:
Declaration of appropriate counter and accumulators as private static fields at the class‐level initialized to 0 (i.e., declared within the class but outside of the main method) for total customers, total discount amount for all
customers, and total charge for all customers
Declaration of appropriate local variables within the main method Input and validation of hours worked, zip code, county, and package type Incrementing of counter and accumulators Display of required output using appropriate accessor methods (i.e., do not use local variables in output
statements)
Sample Input/Output:
Sample #1:
Enter hours used: 25 Enter zip code: 76401 Enter county: Erath Enter package type: A Base Charge for Package A: $9.95 Additional Charge for Package A: $30.00 Surcharge for Zip Code Starting With 7: $0.00 Subtotal for Package A: $39.95 Discount Amount for ERATH County: $7.99 Total Charge for Package A: $31.96 Total Discount Amount for All Packages: $7.99 Total Charge for All Packages $31.96 Average Discount Amount: $7.99 Average Total Charge: $31.96 Total Customers: 1 Package B Savings: $16.80 Package C Savings: $16.00
Sample #2: Enter hours used: 25 Enter zip code: 56789 Enter county: Parker Enter package type: B Base Charge for Package B: $13.95 Additional Charge for Package B: $5.00 Surcharge for Zip Code Starting With 5: $1.75 Subtotal for Package B: $20.70 Discount Amount for PARKER County: $2.07 Total Charge for Package B: $18.63 Total Discount Amount for All Packages: $10.06 Total Charge for All Packages $50.59 Average Discount Amount: $5.03 Average Total Charge: $25.30 Total Customers: 2 Sample #3: Enter hours used: 50 Enter zip code: 76401 Enter county: Erath Enter package type: C Base Charge for Package C: $19.95 Surcharge for Zip Code Starting With 7: $0.00 Subtotal for Package C: $19.95 Discount Amount for ERATH County: $3.99 Total Charge for Package C: $15.96 Total Discount Amount for All Packages: $14.05 Total Charge for All Packages $66.55 Average Discount Amount: $4.68 Average Total Charge: $22.18 Total Customers: 3 Sample #4: Enter hours used: 5 Enter zip code: 12345 Enter county: Winkler Enter package type: A Base Charge for Package A: $9.95 Surcharge for Zip Code Starting With 1: $0.00 Subtotal for Package A: $9.95 Discount Amount for WINKLER County: $0.00 Total Charge for Package A: $9.95 Total Discount Amount for All Packages: $14.05 Total Charge for All Packages $76.50 Average Discount Amount: $3.51 Average Total Charge: $19.12 Total Customers: 4 Enter hours used: -1 Good-bye!