Specifications for Customer Class  Step One: Examine the UML…

Specifications for Customer Class Customer- type: String- name: String

 Step One: Examine the UML diagram for the super class Customer that is shown below. This diagram shows what data variables and what methods will be found within the class. Using the information from the diagram write the code for the super class. NOTE: do not include any data members or methods in any class that are not in the UML diagram.

______________________________________________________________

+Customer(String: type)

+Customer(String: type, String: name)

+getName( ): String

+getType(): String

+setName( String: name):void

+setType(String: type): void

+reportAverageSales( ): double

+toString(): String

Details:

For the one argument constructor set the default value for name to “Microsoft”

The reportSales ( ) method will be abstract and will be over-ridden in the sub classes.

For the toString( ) method, have the method return a String that reads “This customer is from the “type_goes_ here” world, the name of which is “name goes here“.   

The Sub Class Corporate

Extend the super class Customer to make a sub-class called Corporate.java. See the UML diagram below. 

  Corporate

– salesAmount: double

– numPurchases: int

______________________________________________________________

+Corporate( )

+Corporate(String: Name, double: sales, int: purchases)

+getSales( ): double

+setSales(double:sales): void

+getNumPurchases(): int

+setNumPurchases(int purchases): void

+reportAverageSales(): double

+toString( ): String

Details: 

For the no-argument constructor, set the salesAmount to “55000.00” and number of purchases to 5. It will call the one argument constructor from the parent class.

You need to implement the abstract method reportAverageSales( ) in this sub class. This method will return the average amount of each order made based on the total sales amount and the number of purchases.

For the toString( ) method of the Corporate class, have the method make a call to the super class toString( ) method, and then concatenate onto the string from the super class this string :

this company, name goes here made num purchases goes here purchases for a total of

$totalSales goes here.

So, if you had a Corporate object called corporate1 and it called it’s toString( ) method, the string returned should read

This customer is from the corporate world, the name of which is IBM. This company, IBM made 5 purchases for a total of $55,000.0.

The Sub Class Retail.java

Extend the super class Customer to make a sub-class called Retail.java. 

Check the UML diagram below. 

Retail

purchaseAmount: double

-numSales: int

-payType: String

______________________________________________________________

+Retail( )

+Retail(String; name, double: purchase, int: sales,

       String payType)

+getPurchaseAmount( ): double

+getNumSales(): int

+getPayType(): String

+setPurchaseAmount(double: purchases) :void

+setNumSales(int: sales): void

+setPayType(String: payType) :void

+reportAverageSales( ):double

+toString( ): String

Details

For the no-argument constructor, set the purchase amount to 1527.35, number of sales to 4, and pay type to credit card. It will call the one argument constructor from the parent class.

You need to implement the reportAverageSales( ) method of the Retail class. It’s the same formula as the Corporate class calculation 

For the toString( ) method of the retail class, have it call the super class toString( ) method and then concatenate onto its return value this added string:  

This type goes here customer has made num sales go here purchases for a total of $ purchase amount goes here. The purchases were paid for by pay type goes here.

If the retail object was from the no argument constructor, the toString() method would return this:  

This customer is from the retail world, the name of which is Andrew Wing. This retail customer has made 4 purchases for a total of $1527.35. The purchases were paid for by credit card.  

The Test Program CustomerTest.java

Write a test program called CustomerTest.java.

Do the following steps in the exact order shown:

1) Create a Corporate object with a name that you provide…which spent $(made up value) int total sales over (made up value) number of purchases. 

2) Create a Retail object providing your name. You tell me how many purchases you made and what the total value of those purchases are.  You tell me how you paid.

3) Have each object call all of its available getter methods and print out the results to the screen.

4) Have each object call its toString( ) method and print the results to the screen.

5) Change the name of the corporate object to “Something else of your choice”.

6) Now have the corporate object call its getter method to show the change to the corporate name.

  Print that result to the screen 

7) Have each object call its reportAverageSales() method and print the results to the screen. Since sales are always report in dollars and cents you will need to round to two decimal places.

Output should be similar to this:

The Corporate customer Fabricon made 15 purchases for a total of $45235.24

The Retail customer James Kelly made 4 purchases for a total of $1367.55

This customer is from the Corporate world, the name of which is Fabricon.  

This company Fabricon, made 15 purchases for a total of $45235.24.

This customer is from the Retail world, the name of which is James Kelly.  

This Retail customer James Kelly, has made 4 purchases for a total of $1367.55.  

The purchases were paid for by cash.

The Corporate customer Fanshawe College made 15 purchases for a total of $45235.24

The average sale for the corporate customer is $3015.68

The average sale for the retail customer is $341.89