Step 3: Add a basic WineCase class and allow a buyer to select a case of wine to buy. 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" or similar), 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 these four fields. Add a selectWineCase() method to the Browser class which allows a browser to choose a case of wine provided that browser is a buyer. 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 the terminal window about the selection. An example is shown below:            Buyer with ID 6732 has selected wine case with reference             number LO786, a case of 2018 Pinot from Italy of 12 bottles          at £120 Step 4: Allow a buyer to pay for the case of wine. Add a method payForWine() to the Browser 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: at the moment the Website object does not record which browser has entered the store and, conversely, the Browser object also keeps no details of which site it has entered. Let’s deal with that now.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 2PE
icon
Related questions
Question
100%

Step 3: Add a basic WineCase class and allow a buyer to select a case of wine to buy.

  1. 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" or similar), 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 these four fields.
  2. Add a selectWineCase() method to the Browser class which allows a browser to choose a case of wine provided that browser is a buyer. 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.

 

  1. Make the selectWinecase() method print a message to the terminal window about the selection. An example is shown below:

           Buyer with ID 6732 has selected wine case with reference

            number LO786, a case of 2018 Pinot from Italy of 12 bottles

         at £120

Step 4: Allow a buyer to pay for the case of wine.

  1. Add a method payForWine() to the Browser 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: at the moment the Website object does not record which browser has entered the store and, conversely, the Browser object also keeps no details of which site it has entered. Let’s deal with that now.

  1. b) Add another field website to the Browser This field will be used to store a reference (i.e. a pointer) to the website the browser is currently logged into.  Write a mutator method setWebsite().
    • Modify the buyerLogin() method of Website so that after the user is logged into the website, setWebsite() is called with a pointer to that website.

      Think about what this value could be:

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

 

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.

 

And a pointer that points to the object itself is called a self-referencing pointer and has value this.

Amend your code to do this.

 

Next, complete payForWine() by adding a call to the 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.

 

  1. c) Add a method checkout() to the Website class which is passed a parameter which is a pointer to a Browser object representing the browser wishing to purchase a case of wine. The checkout() method should print a message to a terminal window confirming successful completion of the transaction.

 

  1. d) It is decided to give a discount of 10% to every 10th buyer 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 screen and, of course, to reduce the cost of the wine(s).
Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT