Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Step 1: A basic Member class Write a basic Member class with two private fields, email (a String ) and membershipNumber (which you can assume

Step 1: A basic Member class

Write a basic Member class with two private fields, email (a String) and membershipNumber (which you can assume consists of a unique sequence of digits). The constructor for the class should initialise these two fields whenever a Member object is created and be passed suitable argument(s). The simplest way is to assume that the membership number is typed when the object is created; a better way is to get Website to create that number (using Random) and use a mutator to set it).

When you have successfully tested this Member class, introduce a new field loginStatus, which is set by the constructor to false, and a method setLoginStatus(), which is passed a boolean value as an argument. This field will be used whenever the member logs in to one of Tops Travel's websites.

Finally, check that you have included suitable accessor methods. In future steps, you will not necessarily be reminded to include, for example, accessor methods. You will be expected to provide any necessary accessor methods and write sensible code following the general principles and conventions you have been studying in the Introduction to Programming module.

Step 2: A basic Website class

a) Write a basic Website class to represent the web site. The constructor for the class should be passed the name of the website which will typically be "Club 18", "Centre Parks" or "Club Silver" and which should be saved in a field. A second field hits should record the number of browsers who logged into the website and a third field salesTotal should record the amount of money taken at the checkout.

b) Write a method for the class, called memberLogin(), which allows a member to log in to the site. This method is passed a Member object as a parameter and which

  1. uses the member's setLoginStatus() method to "log in" that member to the website;
  2. outputs a welcome message to a terminal window in the format

Club 18 welcomes member 6732, you are now logged in

c) Now write a memberLogout() method.

Step 3: Add a basic Holiday class and allow a member to select a holiday.

  1. Write a basic Holiday class to represent a holiday. A Holiday object has three fields: refNo (a unique sequence of letters and digits), type (e.g. "beach", "touring") and price (the price of the holiday in pounds per person). The constructor for the class should be passed suitable arguments to initialise the three fields.
  2. Add a selectHoliday() method to the Member class which allows a member to choose a holiday provided the user is logged into the appropriate website. This method is passed a Holiday object as a parameter. You should declare a new field holiday in the Member class in order to store the holiday selected.
  3. Make the selectHoliday() method print a message to a terminal window similar to this one

Member 6732 has selected holiday ref number W1473, a touring holiday at 550 per person.

Step 4: Allow a member to pay for the holiday.

  1. Add a method payForHoliday() to the Member class. This method will simply call a method in the Website class to pay for the holiday (i.e. to record the transaction with the website). And here we have a problem because the object from the Member class doesn't keep a record of which website the member is logged into. So we need to do Part (b) below before we go any further.
  2. Add another field website to the Member class. This field is of type Website and will be used to store a reference to the website the member has logged into. Write a corresponding (to emphasise it's in the Member class !) mutator method setWebsite() which allows the field website to be given a value.
    • Modify the memberLogin() method of Website (from Step 2b) so that after the user is logged into the website, setWebsite() is called with a pointer to that website.

So, the setWebsite() method needs to be passed, as an argument, a pointer to the Website object you are currently browsing. This will enable the Member object to record which website it is logged in to.

In fact, the Website object needs to be able to tell the Member object "point to me". To do this, you need to use a self-referencing pointer

Amend your code accordingly and complete payForHoliday() by adding a call to a method checkout() of the Website class. What parameters do you think checkout() will need? Try working this out for yourself and then to check, read c) below which details the parameters needed.

c) Add a method checkout() to the Website class which is passed two parameters: a Member object representing the member purchasing the holiday and a Holiday object representing the holiday. The checkout() method should print a message to a terminal window confirming successful completion of the transaction.

  1. Add code so that the browser is logged off after they have paid for their holiday.
  2. It is decided to give a discount to every 10th member who logs into the website -- if they select and pay for a holiday during this login session then they will receive a 10% discount at checkout. Add a method checkHitDiscount() to the Website class which checks whether a discount is available. Amend your checkout() method to use this new method and, if appropriate, to print a congratulatory message to the terminal window and, of course, to reduce the cost of the holiday(s).

DONE TILL THIS PART WANT YOU TO SOLVE STEP 1: BELOW

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

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 member Login() 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. Tuesday, 01 December 2020 Programming 1 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 listMembers LoggedIn() 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. e) Using a for-each loop, write a new method listMembers LoggedIn() 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 a) 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. b) 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. c) 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. d) 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. e) 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 a) 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. b) Next amend selectHoliday() so that it now calls checkMoney0 before setting the holiday field and then either allows the holiday to be selected or calls the method detailed in c) below. c) Write a new method whoCannot Pay() 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: getWebsiteListo which will return an ArrayList of all the websites under the control of this company. findProfitable Websites which will be given an int argument and will return an ArrayList of all the websites whose sales total is above that argument. findMembers Holiday 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions