Sie sind auf Seite 1von 8

CS202 Programming Assignment 11

Customer Hierarchy Polymorphic Array


Polymorphic Methods and Reference Variables
This programming project will extend your experience with inheritance and class hierarchies to
include work with polymorphic reference variables and the late binding invocation of
polymorphic methods.

Problem Description:
A program is needed that will create a set of Customer Hierarchy objects. But the creation of a
set of reference variables associated with these objects is quite a bit of extra coding and
management of reference variable names, so an array is needed to store the references to each of
these Customer Hierarchy objects. After the Customer Hierarchy objects are stored in the array,
the program needs to process the array of objects to produce a report, displayed on the console,
of the following information.

A listing that contains a String representation of each of the Customer Hierarchy objects
A total of all of the purchase amounts from all of the Customer Hierarchy objects
A listing of only the customers name and purchase amount for the customer who has the
highest purchase amount
A listing of only the customers Person

name and purchase amount for


the customer who has the lowest
purchase amount Customer
A listing that contains a String
representation of each of the
RebateCustomer objects
A total of the rebate amounts of RebateCustomer PreferredCustomer DelinquentCustomer

all of the RebateCustomer


objects
A listing that contains a String representation of each of the PreferredCustomer objects
A total of the discount amounts of all of the PreferredCustomer objects
A listing that contains a String representation of each of the DelinquentCustomer objects
A total of the delinquent penalty amounts of all of the DelinquentCustomer objects

The Customer hierarchy containing the person and various customer classes contains is shown in
the hierarchical diagram on this page. This diagram also illustrates the multiple parent to child
relationships of this set of classes.

Functional Specifications:
Class Hierarchy:
For this project you will need to import the Customer Hierarchy classes that were developed in
the previous programming project into the Eclipse project for this assignment. (If you are
uncertain about how to import source files into an Eclipse project, then you can find the step-by-

Page 1 of 8
step instructions at the end of this document.) The Customer Hierarchy classes from the
previous programming project will need no modifications, but will need to be present in your
Eclipse java project. If you did not successfully create the Customer Hierarchy set of classes in
the last programming assignment, you will need to return to that assignment and complete the
development of this set of classes. If you are had trouble with the previous assignment, you
should seek some help during the office hours of the teaching assistants or the instructor.

Demo/Driver Class:
The demo/driver class for this project will produce more information from this set of Customer
Hierarchy objects than was produced in the demo/driver class in the previous programming
assignment and the demo/driver CustomerHierarchyDemo will be significantly rewritten.

The functionality that is to be provided in this demo/driver class is sufficiently described in the
Problem Description above. The name of this demo/driver class may remain as
CustomerHierarchyDemo since it will be in a new java project.

The data to create the various Customer Hierarchy object types is provided here again in the
following table. The Person object data has been deleted, because no Person objects will be
created as part of the work in this assignments demo/driver program.

Object Name Address Phone Account Account Purchase Days


Type Number Type Amount Overdue
Rebate Tinker Bell 123 Main Street 555-1212 147-A049 Rebate 1750.00
Rebate Shrek 10 Ogre Way 555-ogre 090-G431 Rebate 55.25
Preferred Snow White 111 Dwarf Lane 555-0000 200-A010 Preferred 1566.00
Preferred Sleeping 333 Snooze 555-1111 147-A020 Preferred 599.99
Beauty Drive
Delinquent Cruella 1010 Spotted 555-5555 500-A001 Delinquent 5747.22 90
DeVil Way
Delinquent Prince 123 Castle 555-6123 365-A730 Delinquent 850.00 60
Charming Blvd.

Detailed Design Specifications:


Again to repeat, the Customer Hierarchy classes from the previous programming project will
need no modifications, but they will need to be present in your Eclipse java project.

However, the demo/driver class will need to be significantly rewritten, so it is recommended that
you delete all coding statements except for the object instantiation statements that create the
objects that are listed in the table above.

As required in previous projects all output statements need to be written in the main
method. This will enable you to further gain experience with passing data to a method and
returning data back from a method. Producing output from any of the called methods in this
program is not acceptable.

The demo/driver class must utilize the following Java design techniques to develop this program.
The demo/driver programs main method must create an array that will hold the 6
Customer Hierarchy objects that are listed in the table above. Because these 6 objects are

Page 2 of 8
of different class types, the array will need to be created using a polymorphic reference
variable that has the parent class type of Customer.

Heres an example of an array instantiation with a polymorphic reference variable that we


discussed in class:
Shapes[] shapesList = new Shapes[10];

The demo/driver programs main method must declare the Customer array and then pass
it as an empty array to another method (methods name is up to you, but use good naming
conventions) that will create each of the Customer Hierarchy objects that are listed in the
table above with instantiation statements and store each objects reference variable in one
of the array elements. If you saved the object instantiation statements from the previous
demo/driver version you can moved them to this method and slightly modified them to
create the object instantiation statements needed in this method.

NOTE: The parameter of this called method will need to be defined as a polymorphic
reference variable. Heres an example from our class lectures of a method header
receiving a passed array that needs to be referenced with a polymorphic reference
variable AND an example of the object instantiation and storage into an array element:
public static void populateArray(Shapes shapesArray){
shapesArray [0] = new Rectangle(Rectangle, red,
true, (new Date()), 10, 20);
}

After the objects have been stored in the array and the called methods execution has
ended, the demo/driver programs main method will continue by printing out a listing of
each of the Customer Hierarchy objects that are stored in the array. (HINT: Each class
definition should include a toString() method that can produce and return this string
representation that can be printed out.)
The demo/driver programs main method must pass the filled array to another method
(again naming is up to you) that will process through the objects in the array and add up
all of the various purchase amounts and then return the total amount of the purchases.
The main method will printout the returned total purchases amount in a clearly labeled
and well formatted manner.

Heres an example of getting an objects data value from an objects instance method
when the objects reference is stored in an array:
shapesArray[arrayIndex].getArea();

The demo/driver programs main method must pass the filled array to another method
that will process through the objects in the array and find the object that has the
largest/highest purchase amount. This method will return the index of that object back to
the main method, where the customer name and purchase amount of this object will be
printed out in a clearly labeled and well formatted manner.
The demo/driver programs main method must pass the filled array to another method
that will process through the objects in the array and find the object that has the
Page 3 of 8
smallest/lowest purchase amount. This method will return the index of that object back
to the main method, where the customer name and purchase amount of this object will be
printed out in a clearly labeled and well formatted manner.
The demo/driver programs main method must now process through the objects in the
array and for each RebateCustomer object that it finds in the array, it must print out the
String representation of that customer object. There should be a brief label indicating that
the following is a listing of RebateCustomer objects. This processing of the array will
require the technical use of the instanceof operator that was discussed in Chapter 10
Sec 10.7.

Heres an example of using the instanceof operator to determine the type of the
object that is referenced with a polymorphic reference variable:
if (shapesArray[arrayIndex] instanceof Rectangle)
count++;

The demo/driver programs main method must pass the filled array to another method
(naming is up to you) that will process through the objects in the array and total up the
rebate amounts given to all of the RebateCustomer objects. This method will need to also
utilize the instanceof operator to accomplish its task. This method will return the
total back to the main method, where it will be print out in a clearly labeled and well
formatted manner.
The demo/driver programs main method must also process the array for the
PreferredCustomer objects and the DelinquentCustomer objects as it did for the
RebateCustomers in the previous two bulleted task. That is a listing of
PreferredCustomer objects will be created and the total of all of their discounted amounts
will be accumulated and printed out and the same listing will also be done for the
DelinquentCustomer objects and the total of their delinquent penalty amounts will be
accumulated and printed out.

An example of the execution output expected from this program can be seen below in the
Example Execution section which is provided below.

Submission Requirements: When you have completed your development, testing and
commenting of the Java class and the Java program within this Java project, then export the
project as an archived/zipped file that is named your last name, first name and the assignment
name (For Example: LastnameFirstnameProgAssign11). Return to the Desire2Learn(D2L)
assignment item and complete the submission steps to upload and submit your archived/zipped
file via the D2L assignment item.

Page 4 of 8
Example Execution:
List of all Customers
Name: Shrek The highlighting of the section headings
Address: 10 Ogre Way in this output is done only for easy locating
Telephone: 555-Ogre of each section. Highlighting is not required
Customer Number: 090-G431 from your programs output.
Customer Type: Rebate
Total Purchases: 55.25
Total Rebate Percent: 10.0%
Total Owed Minus Discount: 49.73

Name: Tinker Bell


Address: 123 Main Street
Telephone: 555-1212
Customer Number: 147-A049
Customer Type: Rebate
Total Purchases: 1750.00
Total Rebate Percent: 20.0%
Total Owed Minus Discount: 1400.00

Name: Snow White


Address: 111 Dwarf Lane
Telephone: 555-0000
Customer Number: 200-A010
Customer Type: Preferred
Total Purchases: 1566.00
Total Discount Percent: 7.0%
Total Owed Minus Discount: 1456.38

Name: Sleeping Beauty


Address: 333 Snooze Drive
Telephone: 555-1111
Customer Number: 147-A020
Customer Type: Preferred
Total Purchases: 599.99
Total Discount Percent: 5.0%
Total Owed Minus Discount: 569.99

Name: Prince Charming


Address: 123 Castle Blvd
Telephone: 555-6123
Customer Number: 365-A730
Customer Type: Delinquent
Total Purchases: 850.00
Total Delinquncy Penalty: 10.00%
Total Owed Plus Delinquency Penalty: 935.00

Name: Cruella DeVil


Address: 1010 Spotted Way
Telephone: 555-5555
Customer Number: 500-A001
Customer Type: Delinquent
Total Purchases: 5747.22
Total Delinquncy Penalty: 15.00%
Total Owed Plus Delinquency Penalty: 6609.30

Page 5 of 8
The total customer purchases are: 10568.46

The customer with the highest purchases is


Name: Cruella DeVil
TotalPurchases: 5747.22

The customer with the lowest purchases is


Name: Shrek
TotalPurchases: 55.25

List of all Rebate Customers


Name: Shrek
Address: 10 Ogre Way
Telephone: 555-Ogre
Customer Number: 090-G431
Customer Type: Rebate
Total Purchases: 55.25
Total Rebate Percent: 10.0%
Total Owed Minus Discount: 49.73

Name: Tinker Bell


Address: 123 Main Street
Telephone: 555-1212
Customer Number: 147-A049
Customer Type: Rebate
Total Purchases: 1750.00
Total Rebate Percent: 20.0%
Total Owed Minus Discount: 1400.00

The total customer rebates are: 355.53

List of all Preferred Customers


Name: Snow White
Address: 111 Dwarf Lane
Telephone: 555-0000
Customer Number: 200-A010
Customer Type: Preferred
Total Purchases: 1566.00
Total Discount Percent: 7.0%
Total Owed Minus Discount: 1456.38

Name: Sleeping Beauty


Address: 333 Snooze Drive
Telephone: 555-1111
Customer Number: 147-A020
Customer Type: Preferred
Total Purchases: 599.99
Total Discount Percent: 5.0%
Total Owed Minus Discount: 569.99

The total customer discounts are: 139.62

Page 6 of 8
List of all Delinquent Customers
Name: Prince Charming
Address: 123 Castle Blvd
Telephone: 555-6123
Customer Number: 365-A730
Customer Type: Delinquent
Total Purchases: 850.00
Total Delinquncy Penalty: 10.00%
Total Owed Plus Delinquency Penalty: 935.00

Name: Cruella DeVil


Address: 1010 Spotted Way
Telephone: 555-5555
Customer Number: 500-A001
Customer Type: Delinquent
Total Purchases: 5747.22
Total Delinquncy Penalty: 15.00%
Total Owed Plus Delinquency Penalty: 6609.30

The total customer delinquency penalties are: 947.08

Page 7 of 8
Eclipse Source File Importing Instructions:
To import a single Java source file into an Eclipse Java project, follow these steps:
1. Click to select the src folder in the Java project where you want to import a separate Java
source file (not an entire Java project).
2. Click on File > Import and select General to expand it in the Import dialog window
3. Click on File System to select it and click the Next button.
4. At the top of the next window that pops-open, click on the Browse button to navigate
through your file systems to find the folder or directory where the Java source code file is
stored. Click the folder or directory to select it and then click on the Ok button. NOTE:
the location of the desired file can be within the src folder of another project.
5. In the list of the contents of that folder click on the checkbox in front of the file or files
that you want to import into this Java project.
6. Look down to the middle of this window and verify the name of the folder into which
you want to copy the Java source code file. It may be necessary for you to
Browse/Navigate through your storage areas to find the correct destination src folder,
where you want to store a copy of the desired source code file.
7. Click the Finish button. The desired Java source code file should be added to the Java
Project

Page 8 of 8

Das könnte Ihnen auch gefallen