Available: Mon November 21
Due: Sat, December 3, extended till Wed, Dec 7, 22:00
This assignment is to be done in TEAMS
OF TWO PEOPLE. The assignment should be submitted only once by a
member of your team, but please ensure that the identification material
contains the information for both team members. Follow the
"Regulations and Instructions that Apply to All Assignments" that is
available on the course web page.
For this assignment, classes should be in files with names that match the name
of the class. Make sure the method names are exactly
the ones specified, because the marking will be done with JUnit tests.
In this question, you will create a class Client that will store information about the clients of an online business.
Attributes:
Client objects will store the following information for each client:
Constructors:
As a Client object is created, a value should be supplied for the name, email address, and an initial password. The credit should be set to 10 dollars.
Here is the constructor header:
Accessors and Modifiers:
Public accessor methods should be available for the name, email, and credit. Here are the method headers:
A public modifier method should be available for the email address. Clients are not allowed to change their names. Here is the method header:
Additional methods
There should also be a method that compares a password entered by the client with the stored password. This method should return true if the client entered the correct password, and false otherwise.
There should be a method to change the client’s password. A password change is only permitted if the old password can be given, so the two parameters are the entered password and a new password. The entered password is compared with the password stored inside the object. If the password is correct, then the new password replaces the previous password inside the object. To indicate that the operation was successful, the method should return true. If the entered password was incorrect, the password stored in the object should remain unchanged and the method should return false.
You should be very careful that a client object never gives out the stored password.
Here are the method headers:
Finally, because a client can use credit (part of it or all) to buy an item, the following method should deduct the amount passed as parameter from the credit. It returns true if the amount deducted is not bigger than the credit; otherwise it returns false and the credit stays unchanged.
· public boolean reduceAmountCredited (int amount)
A UML diagram for the class follows:

Testing
You can test your Client class using the class A5Q1.java that should produce the output A5Q1.txt. Also test your Client class using the JUnit class ClientTest.java. You should do more testing for yourself, but make sure that the tests from TestClient.java (without modification) run properly.
In this question, you will create a class Item that will store information about items that can be purchased.
A UML diagram for the class follows:

There are some values that apply to all Item objects:
Individual Item objects will store the following for each item:
As an Item object is created, a cost value should be supplied for each instance variable. There should also be accessor methods for each of the above values. There should be a modifier method for the price.
Additional methods
Testing
Test your Item class using the class A5Q2.java that should produce exactly the output A5Q2.txt. You can run more tests for yourself or test with the Junit file ItemTest.java, but make sure the class A5Q2.java (non-modified) produces the required output.
In this question, you will create a class Purchase that will store information about a specific purchase.
When a client buys an item, this class will represent the association between a Client object and one or more Item objects that are purchased as part of this transaction.
Attributes:
Individual Purchase objects will store the following for each transaction:
Constructor:
The constructor header is as follows:
Each time a new Purchase object is created, the next highest bill number not previously used should be stored. The bill number for the very first Purchase object created should be 1000.
Also at the time of creation, the client reference, the references to the Item objects, and the current day number should be stored. Then, the cost of the purchase should be determined automatically by calculating the sum of the prices of the items, and adding the shipping cost (2$ for handling, plus 1$ for each item delivered). If the buyer has an amount of credit, it will be used to reduce (partially or totally) the cost of the purchase. The number of copies available for each item purchased should be reduced by 1 when the purchase happens. Note that if for an item no copy is available, the item is not delivered. The purchase transaction continues, but the cost of that item is not included in the total cost. If none of the items of the purchase are available, then there are no shipping fees.
Accessors and Modifiers:
There should be public accessor methods for the bill number and the purchase day number
Here are the method headers:
Additional methods
There is a method getClientName()that returns the name of the client associated with the transaction. Note that the name is not directly stored in the transaction; instead, the method should ask the associated client object for its name.
There is a method toString()that returns a String containing the information about the purchase transaction:
The advantage of creating a toString() method is that it can be used directly for printing results for an object. For example, if myPurchase is a purchase: System.out.println(myPurchase) calls the toString() method and displays the returned string. Note that the following constant allows to add a newline to a String: final String newLine = System.getProperty("line.separator"); for example: String result = "Hello!" + newLine;
There is a method includesItem( ) that returns true if the item supplied as a parameter is one of the items that is part of this transaction. If the specified item is not part of the transaction, the method should return false.
You can add more private methods or variables if needed.
Here are the method headers:
A UML diagram for the class follows:

Testing
Test your Purchase class using the class A5Q3.java that should produce exactly the output A5Q3.txt. You can run more tests for yourself or with the Junit file PurchaseTest.java, but make sure the class A5Q3.java (non-modified) produces the required output.
In this question, you will create a class Journal that will store the collection of Purchase transactions, and print some summary statements.
Because we do not want to allow more than one collection of transactions, the class Journal will use a (private) static array variable to store references to Purchase objects. This also means that no Journal objects are created. With no Journal objects, all variables and methods must be static.
Besides the pointer to the array of purchases, there is a variable for the maximum number of entries in the journal (a constant in fact), and a variable to store the actual number of purchases that took place.
The method initialize( ) should create capacity for a specified number of Purchase objects to be stored in an array in the Journal. However, no Purchase objects are added at this time. The variable numPurchases can be initializes with zero, and later used to keep track how much of the array is used.
The method add( ) will attempt to add the specified Purchase object to the Journal. If there is space to hold another Purchase object, the object should be added. If the Journal has no more room to store additional objects, an error message should be printed.
The method purchasesForClient(...) returns
an array (of the right size) of total costs for the purchases made by a Client passed as parameter.
The method printPurchasesItem(...) prints the names of all the clients that tried to buy the item
passed as parameter, and the corresponding dates of purchase.
The method calculateTotalPurchases(...) returns the sum of all the costs of the purchases registered in the journal.
Here are the method headers:
A UML diagram for the class follows:

Testing
Test your Journal class using the class A5Q4.java that should produce exactly the output A5Q4.txt. You can run more tests for yourself, but make sure the class A5Q4.java (non-modified) produces the required output.