CSCE 155

Homework Assignment 5: 

GUI Design in OO Fashion --- Inheritance and Polymorphism

Assigned:  November 15, 2004

Due: Start of Class, November 29, 2004

 

Note: This assignment is to be completed individually - collaboration is strictly prohibited.

Points:  100 points

 

Problem Description

 

In Homework Assignment 4, you created an application that implements a grocery store.  In this assignment, you are required to extend the application using inheritance and polymorphism.

 

Now, we want to differentiate the customers into several types: general customers, cardMember customers and senior customers.  The cardMember customer class and the senior customer class should be inherited from the general customer class. For a cardMember customer, it has two additional attributes: a cardID (a String data member) and a discount percentage (e.g., 5.3%).  For a senior customer, it has two additional attributes as well: age (an integer) and discount percentage (e.g., 2.7%).  The customer class that you have built in Homework Assignment 4 should be the general customer class.

 

For different types of customers, your program should correctly compute the total amount of their purchases based on the discount percentages they have, and show their bills accordingly. For example, in the bill of a cardMember customer, it should reflect that the customer is a cardMember and show the customer’s cardID. 

 

Add a function to compute the total sales of the grocery store. Here, you should use polymorphism. The idea is that you should define the method called “computeTotalPurchaseAmount” to compute the total amount of purchases of each customer in the classes of general customer, cardMember customer and senior customer, respectively. (Note that here we require the same method header or prototype to be used in all three implementations!)  Then in the GroceryStore class, you are required to have a method that computes the total sale of the entire grocery store by summarizing all the purchases of all the customers.  

 

Your new ShoppingCard class is required have new features to accommodate the new types of customers.  Please see Figure 1 as an example.

 

Figure 1.  Example of a new ShoppingCart class.  If the member type is not selected, then it is assumed that the customer is a general customer.

 

Your new GroceryStore class is required have a new button and a new text field.  The new button is for “Total Sale”.  When the user clicks on this button, GroceryStore will compute the total sale of all purchases of all customers and output the amount in the new text field.

 

In addition to the classes you created in Homework Assignment 4, you should include several new classes:

  1. CardMemberCustomer: This class is for cardMember customer.
  2. SeniorCustomer: This class is for senior customer.

 

Test

 

To test your program, input at least 5 different customers, and among these at least 2 customers make more than 2 purchases.  Some of these customers should be of the Customer class, some should be of the CardMemberCustomer class, and some should be of the SeniorCustomer class.  Then test to compute the total sales of the grocery store. Turn in your test results.

 

Supplied Solution Components

 

A sample homework 4 solution will be provided as soon as possible.

 

Challenge - Extra Credit (20 points)

 

Add an option to your application that allows the user to query for the information of a specific customer by name.  So, when this query window pops up, the user can enter a customer’s name (and only the customer’s name), and then the window will display the information of the customer.  How to display is your choice. 

 

Notice you are required to use polymorphism to implement this.  That is, you are required to define and implement a method called printCustomerInfo for all different classes of customers.

 

Submission Procedure

 

This assignment is due on November 29, 2004 at the start of class. Your grade will be reduced by 10% for each day it is late. It is recommended you read the grading policy and grading guidelines on the course website for a complete explanation of how the assignments will be graded. Remember, your program should follow good programming style, include plenty of comments, and perform all of the functionality outlined above.

After completing the assignment, you must “handin” the following files on-line:

1.      Source files: *.java

2.      Compiled files: *.class

3.      Readme file: README.TXT(Plus test results)

In addition, you must submit a stapled paper copy of your source code (and README file), please write down your CSE email on your paper copy.  Both of these steps must be done by the start of class on the day the assignment is due.