Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.04 KB | None | 0 0
  1. Individual Assessed Coursework
  2. November 2010
  3.  
  4. Scenario: Wine Direct is an attempt by a cooperative to sell their wine reserves directly to the public. Wine is only sold by the case. People who are interested in buying the wine have to submit their details online and, once accepted, are then given a unique ID (via email). Later they can use this ID to gain access to the website and perhaps select a particular wine case and go to the checkout to pay for it. For the purposes of this assessment, you may assume that only one person can log onto the web site at any one time.
  5.  
  6. You are to model this scenario using a BlueJ project Wine Direct following these steps:
  7.  
  8. Step 1: A basic Browser class
  9. Write a basic Browser class with three private fields, yearOfBirth, email (a String) and iD (which you can assume consists of a unique sequence of digits).
  10.  
  11. There are going to be two kinds of browsers: those who already have an ID (and so can purchase the wine straightaway) and those who do not. Hence this class will need two constructors: one for each type of browser. One constructor will be passed three arguments and the other two arguments – the third field needs to be set to a suitable value.
  12.  
  13. Now introduce a new field loggedIn, which is set by the constructor and a method setLoginStatus(), which is passed a boolean value as an argument. This method will be used whenever the potential buyer logs in the Wine Direct website.
  14.  
  15. 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.
  16.  
  17. Step 2: A basic Website class
  18. a) Write a basic Website class to represent the web site. A field hits should record the number of browsers who logged onto the website and a second field salesTotal which should record the amount of money taken at the checkout. There should be no other fields.
  19.  
  20. There are two types of browsers who access this web site: those who already have their ID and those who do not. Part of the web site allows the former to simply log in and to then be able to access all areas of the site; those who do not already have ID must submit their personal details and, once these have been checked, then they too are logged in and are able to access all areas of the web site.
  21.  
  22. b) Write a method for the class, called browserLogin(), which allows a browser who already has an ID to log in to the site. This method is passed a Browser object as a parameter and which
  23. i) uses the browser's setLoginStatus() method to "log in" that browser to the website;
  24. ii) outputs a welcome message to a terminal window in the format
  25. Wine Direct welcomes browser 6732, you are now logged in.
  26. Extra mark: use an accessor method to print out part of the welcome message.
  27.  
  28. c) Write a method becomeBuyer() which is also passed a Browser object as a parameter and which then checks that the potential browser is over the age of 18 and is able to make a purchase. Of course, in real life more checks would have to be made . You also don't need to worry about checking for an accurate age i.e. you don't need to include months and days in your calculation. Unless you want to that is .
  29.  
  30. Anyhow, if the browser is indeed old enough then the method sets the browser's iD field (see paragraph below) and calls the method browserLogin() to welcome the new browser.
  31.  
  32. To set the browser's iD field, you have a choice: either set it to 999 or, for more marks, set it to a random value. To do this, you need to use an object from the Random class as follows. Firstly, write the code import java.util.Random before the class header of Website. Then use the BlueJ Help menu to find out about the Random class and which method from that class is most appropriate to use here.
  33. Step 3: Add a basic WineCase class and allow a browser to select a case of wine.
  34.  
  35. a) Write a basic WineCase class to represent a case of wine. A WineCase object has four fields: refNo (a unique sequence of letters and digits), description (e.g. "chablis", "white burgundy"), noOfBottles (in the case) and price (the price of the case in pounds). The constructor for the class should be passed suitable arguments to initialise the three fields.
  36. b) Add a selectWineCase() method to the Browser class which allows a browser to choose a case of wine provided the user is logged into the website. This method is passed a WineCase object as a parameter. You should declare a new field wineCase in the Browser class in order to store the case of wine selected.Make the selectWinecase() method print a message to a terminal window of the form
  37. Browser 6732 has selected wine case ref number W1473 of 12 Chablis at £120.
  38.  
  39. Step 4: Allow a Browser to pay for the case of wine.
  40. a) Add a method payForWine() to the Browser class. This method will simply call a method in the Website class to pay for the wine i.e. to record the transaction with the website. And here we have a problem because the object from the Browser class doesn't keep a record of the website the browser is logged into. So we need to do Part (b) below before we go any further.
  41.  
  42. b) Add another field website to the Browser class. This field is of type Website and will be used to store a reference to the website the browser is logged into. Write a corresponding mutator method setWebsite() which allows the field website to be given a value.
  43. • Modify the browserLogin() 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.
  44. Think about this.
  45. 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 Browser object to record which website it is logged in to.
  46.  
  47. In fact, the Website object needs to be able to tell the Browser object "point to me". That is, the Website object needs a pointer to itself.
  48.  
  49. And a pointer that points to the object itself is called a self-referencing pointer and has value this.
  50. So the argument we need to pass to setWebsite() is this.
  51.  
  52. Amend your code accordingly and complete payForWine() 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.
  53.  
  54. c) Add a method checkout() to the Website class which is passed two parameters: a Browser object representing the Browser purchasing a WineCase object representing the wine. The checkout() method should print a message to a terminal window confirming successful completion of the transaction.
  55.  
  56. d) Add code that allows the browser to log off after they have paid for their wine.
  57.  
  58. e) It is decided to give a discount to every 10th Browser who logs into the website -- if they select and pay for a case of wine 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 wine(s).
  59.  
  60.  
  61.  
  62. Finally !
  63.  
  64. Note that not every detail to make this code more realistic is mentioned here ! -- think about this yourselves and consider e.g. what checks do you need in your code ? Remember your original Account class and the Naïve Ticket Machine project -- how were they improved ?
  65.  
  66. Hand in details
  67. • You will need to submit a hard copy of the source code for the Wine Direct project. Your Java group number (1, 2, 3 or CN) should be written on the front page. All work should be handed in inside a clear plastic wallet and should be handed in at the latest at the lecture on Tuesday 23rd November 2010.
  68.  
  69. Note that by the act of following these instructions and handing your work in, it is deemed that you have read and understand the rules on plagiarism as written in your student handbook.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement