Question: Step 1 : a simple Member class Write a simple Member class which has three private fields called name, id and pinNumber. The member ID

Step 1: a simple Member class
Write a simple Member class which has three private fields called name, id and pinNumber.
The member ID consists of a unique sequence of letters and digits1* of length at most 10 and the pin
number consists of a sequence of four digits (which could start with the digit zero. The constructor
for the class should be passed suitable arguments to initialise these three fields in the order
specified above whenever a Member object is created.
class should have suitable accessor & mutator methods.
Step 2: A simple Store class
a) Write a simple Store class to represent the store. The constructor for the class should only
be passed the name of the store which is then stored in a field called storeName. A
second field total should record the amount of money taken at the checkout.
b) Write a method for the class, called memberRegister1() which allows the member to
gain entry to the store. This method is passed an argument that is a pointer to a Member
object i.e an argument of type Member. At this stage, simply get this method to output a
welcome message to a terminal window in a format identical to the example below:
Salford Thrifty Store welcomes Andy (id:SGT006732)
where Salford Thrifty Store is the name of the store, Andy is the name of the
member whose ID then follows.
c) Next, write a method for the class, called memberRegister2() which also allows the
member to gain entry to the store. However, this method differs from the previous method
in that is passed the member's name, id and pin number as parameters in this particular
order and then creates a Member object which, for now, is temporarily stored in a local
variable called member
Step 3: Enhancements to the Store and Member classes
a) Add a fourth field store to the Member class. This field is of type Store and will be
used to hold a reference to the store the member has entered.
b) Write a mutator method setStore()which is passed a pointer called store to the store
into which the member has entered.
c) Read the whole of this part c) before trying to write any code.
Now this method, setStore() needs to be called from both memberRegister()
methods which are in the class Store. So, each of these calls is a call to a method in
another class and so both are external method calls.
Next, for each of these calls, think about what the argument to this method should be.
Well, setStore() needs to be passed, as an argument, a pointer to the Store
object that you are currently in.
In fact, the Store object needs to be able to tell the Member object "point to me".
To do this, you need to use a self-referencing pointer.
Such a pointer was described in detail in the Supplementary lecture slides SM1.40-1.47.
Now if you understand the explanation above you can write both calls to setStore()
in Store.
tep 4: Add a simple Item class and allow a member to select an item.
a) Write a simple Item class to represent an item of food or drink. An Item object has two
fields, name and price -- the latter should be stored as an int representing pence. The
constructor for the class should be passed arguments to initialise these two fields in the
order specified above whenever an Item object is created.
b) Write an accessor method getPrice() that simply returns the price of an item as an int
and then another method called getPriceString() method that simply
returns price as a String.
c) Add a selectItem() method to the Member class which is passed an Item object as a
parameter. You should declare a new field item in the Member class in order to store the
item selected. Finally, for this step, make the selectItem() method print a message to a
terminal window which outputs the name of the member, the item purchased and the cost of
that item on a single line in the exact format given here
Andy has selected Wholemeal Medium Sliced Loaf at 54p
or
Andy has selected Fresh Whole Chicken at 304p
depending on whether or not the item costs less (or more) than a pound
Step 5: Allow a member to buy the item.
a) Add an extra field money to the Member class to represent the amount of money the
member has in their wallet or purse. Initialise the field with 500 pence.
b) Add a method checkout() to the Store class which is passed two parameters: an int
representing the amount of money tendered to pay for the item and a Member object
representing the member at the checkout in that order. This amount of money may be
different to the cost of the item e.g. the member may tender a 1 coin (represented by 100p)
to pay for an item of value 54p. The checkout() method should print a message to a
terminal window identical to the example shown below:
Salford Thrifty Store: Serving Andy
Your basket contains
Fresh Whole Chicken at 304p
You have tendered 400p
Your change is 96p
c) Add a method goToCheckout() to the Member class which is passed an int parameter
called payment representing the money the member is tendering to pay for the item.

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!