Individual Assessed Coursework 4 December 2020
As in previous homeworks, you must use the names of fields (and all other variables and methods) as they are exactly specified in this document.
Noting also for method names that if you have a variable called numberOfOwners, then a mutator for this field is called setNumberOfOwners and the corresponding accessor is called getNumberOfOwners.
All fields need to have accessors & mutators.
Scenario: this homework builds upon the previous homework which modelled the Tops Travel Club, a web-based travel agency. It is therefore assumed that your model satisfies the requirements of the previous homework.
Remember that one of the deficiencies in the previous homework was the fact that your model only allowed one member of the club at a time to be logged into a website. This was because you could not keep track of several members at a time since you were not familiar with the ArrayList class which was introduced in Chapter 4 and which can now be used for this purpose.
It is important before you proceed any further that you have worked your way through both the Notebook projects and the Zoo project examples (from the module book and the lectures respectively). Also, make sure that you have made all the necessary modifications to your Homework 3 !
Your homework is to enhance your existing model with the functionality detailed below.
Steps 1, 2 and 3 below are mainly concerned with changing the code from your earlier homework to the new situation and have been described in some detail in order to help you. The later steps require you to add extra functionality.
Start with your previous homework which you should now call “Tops Travel Club using Basket Step 1″using the Save As option.
When you have successfully completed each step, save your project (using the Save As option) in a similar way at the end of each subsequent step.
Step 1: Allow several members to log on to a particular web site at one time
a) Introduce loggedInList as a field in the Website class which will be used to store those members who are presently logged into the website. It should be declared to be an ArrayList collection class object which stores objects from the class Member and it should have a declaration similar to that of animalCollection in the Zoo class.
b) Modify the Website class’s memberLogin() method so that each member who logs in is added to the list of members logged on.
Test your code by creating two new members, logging each in and then using the Object Inspector to see whether their details are safely stored in loggedInList.
c) Write a method, getNumberOfUsers() in the Website class, to return the number of members presently logged into the web site.
d) Add a toString() method to the Member class which returns a member’s details in this exact format below noting that you only output the primitive data fields (i.e. not any pointer fields):
membership number : 6732
email : a.anyone@edu.salford.ac.uk
logged in status : false
. Test your code by creating a new member and calling its toString() method.
e) Using a for-each loop, write a new method listMembersLoggedIn() for the Website class. It should print out the details of each member in the list of members logged on using the Member‘s toString() method.
Step 2: Allow a member to book a holiday for multiple people
- Write a simple Friend class with two private fields, name (a String) and money (a field which represents how much money this friend has to spend. The constructor for the class should be passed suitable arguments to initialise these two fields whenever a Friend object is created as well as any appropriate accessor / mutators.
- Introduce companions as a field in the Member class which will be used to store the holiday companions of the member. It should be declared to be an ArrayList.
- Add a storeFriend() method to Member. Test your code by creating two new friends, adding them to the list of companions and then using the Object Inspector to see whether their details are safely stored in companions.
- Add a toString() method to the Friend class which returns the friend’s details. Test your code by creating a new friend and calling its toString() method.
- Using a for-each loop, write a new method listFriends() for the Member class. It should print out the details of each friend in the list of companions using the Friend‘s toString() method details in the same format as 1d) above.
Test your code by creating two new friends, adding them to the list of companions and then calling listFriends().
Step 3: Introduce some payment checks
- When a member books a holiday for himself/herself and his/her companions, it is, of course, essential that they are each able to afford the holiday. Write a method checkMoney() which is given the cost of the holiday and then checks whether the member and each friend can afford the holiday. When you write this method, you will also need to add another field to Member called money.
- Next amend selectHoliday() so that it now calls checkMoney() before setting the holiday field and then either allows the holiday to be selected or calls the method detailed in c) below.
- Write a new method whoCannotPay() which also takes the cost of the holiday as a parameter and which outputs a message for each person (including, if applicable, the member) who cannot afford this holiday. The output must be in the format below: Paul has insufficient money to afford this holiday where Paul is the name of the friend.
Test your code by e.g. creating a member (with £500) and two new friends, one with £750 and the other £300, adding them to the list of companions, and then calling selectHoliday() to select a holiday at £400. Continue to test with a variety of similar examples.
Step 4: Amendments to existing code
If you have not already done so, amend payForHoliday() so that the member and companions are debited for the cost of their holidays. Think of this as the member collecting the money from each friend (and the member itself) before going to pay.
Note also that although the cost of a holiday is quoted in whole pounds, often various taxes are added to a holiday cost and these would also need to be taken into account when calculating amounts of money and so you need to change the data type of all relevant fields to reflect this.
Make sure that your model includes all necessary transactions.
Step 5 with two challenging parts
The company now decides to allow for multiple websites. Write a new class, invoked with new Company(), whose job is to keep track of all the websites for a given company.
This new class will have the following methods:
- getWebsiteList() which will return an ArrayList of all the websites under the control of this company.
- findProfitableWebsites() which will be given an int argument and will return an ArrayList of all the websites whose sales total is above that argument.
- findMembersHoliday() which will be given an Holiday argument and will return an ArrayList of all those members logged onto any company website who have chosen this particular holiday.