Question: Step 3 : Allow a member to put back items A member might put back an item because they changed their mind about that item

Step 3: Allow a member to "put back" items
A member might put back an item because they changed their mind about that item or because they have insufficient money to pay when they go to the checkout.
We could write code to deal with this in the Store class or we could write code to deal with this in the Member class, but it does seem more straightforward to check for this before you get to the actual checkout i.e. in the Member class, so that is the approach we shall adopt.
a) Write a method putItemBack()for the Member class which removes an item from the shopping basket. It is passed an int parameter indicating the position in the list of the item you wish to remove.
b) Write a second method putItemBack()for the Member class that is passed a String parameter indicating the name of the item to be removed. Note that this method has the same name as the method in Part a) but has a different signature (so this is allowed).
c) Write a method putExpensiveItemsBack()for the Member class which removes items (note the plural) with a price greater than or equal to a specified amount. This latter value is passed to the method as a parameter. Hint: Worksheet 4 includes the following in Worksheet Exercise 1: Section 4.12.1 and Section 4.12.2 which explains the pitfalls of removing elements whilst in a loop: read this carefully and then complete Exercise 4.39.
d) Next add a field to the Store class called maxMumberOfItems that stores the maximum number of items that a basket should hold. Then, write a method basketOverFull(), also for the Store class, that is passed a basket object as the method argument (Similar to the basket field you added in Step 1(a)). This method should be called from checkout() and if the basket does contain more than the allowed limit (maxMumberOfItems) then it returns true, otherwise it returns false. Depending on this value, the member is allowed (or not) to pay for their items.
Step 4 with code enhancements:
a) Write a method showMembers() in the Store class that outputs details of all the members registered to shop at a store in a format identical to the example shown below.
The members of this store are
Andy with id SGT006732
Imran with id GGA987658
In order for this method to work correctly, you will need to add a new feature to the Store class (i.e and ArrayList of members ) and a new method in Member(toString()).
One obvious enhancement is to change the output so that it produces the outputs using pound signs e.g.3.04 and 49p. To do this, you should first return to the getPriceString() method of the Item class and make sure that this method returns the price of an item in the new format. Once you have done this, it is helpful to perform a little reorganisation. Move the code that actually does the conversion into a second private method convertPenceToString() that returns a String and call this new method from getPriceString().
You can copy and reuse the method convertPenceToString()in other classes where it is needed.(Having "duplicate code" is not an ideal situation and later we will discuss how to avoid it but for now do not worry).
Hint: After this when the checkout method in the Store class is called a message to the terminal window can now be of the form:
Salford Thrifty Store: Serving Andy
Your basket contains 2 items:
Fresh Whole Chicken at 3.04p
Milk at 89p
The total cost is 3.93p
You have tendered 4.00p
Your change is 7p
Hand in details
You will need to upload three separate .java files (Store.java, Member.java and Item.java - to separate upload areas on BB.
The deadline to do this is 16.00 Wednesday 11th December.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!