Beruflich Dokumente
Kultur Dokumente
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
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.
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.
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
Page 5 of 8
The total customer purchases are: 10568.46
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
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