JKL Restaurant maintains a members’ club for its customers. There are three levels of membership: (1) Basic, (2) Silver, and (3) Gold. A certain member has to be exactly a Basic, Silver, or Gold member at any point in time. Whenever a member spends money at JKL, he/she gets points and as these points are accumulated, one can redeem one or more $20 dining certificates. Each Gold member can also get an annual appreciation present from the restaurant.

Activity Gold Silver Basic
Getting points Rounded up nearest integer value Rounded up nearest integer Rounded up nearest integer
(purchase value *110%) (purchase value *105%) of purchase
---------------------------------------------------------------------------------------------------------------------------------------------
Redeeming a dining
certificate Use 300 points use 300 points use 300 points
---------------------------------------------------------------------------------------------------------------------------------------------
Getting annual
appreciation present yes no no

Define an abstract superclass called Member under which there are three concrete classes: Gold, Silver, and Basic.

Private instance variables in class Member include

  • a String memberID
  • a String lastName
  • a String firstName
  • an integer currentTotalPoints

Private static (class) variable in class Member: noOfPointsPerCert.

you declare this private attribute:

Please initialize it to 300 when private static int noOfPointsPerCert = 300;

This static variable will also be inherited by each subclass. Do not declare an instance variable for holding the membership type of a particular member.

The class Member should have a 4-parameter constructor that accepts four input parameter values for each of the instance variables above. The class Member should have a set method and a get method for each of the instance variables above. It should also have a static set method and a static get method for the static variable noOfPointsPerCert. These are all concrete methods. These are to be inherited and used by all those subclasses.

The class Member should have an abstract method addPoints(double purchaseValue). When implemented in a subclass, it should add the correct number of points to a member’s account with the raw incoming purchase value for getting points, according to the rules of adding points for that level of membership. The class Member should have a concrete method redeemCertificates(integer noOfCertificatesRequested). There can be two different approaches for writing this method. The first approach: it calculates the number of certificates that a member can redeem. If the member does not have enough points to redeem the requested number of certificates, it should tell the user a sorry message and refuse to grant any certificates. If the redemption is possible, it should deduct the correct number of points from a member’s account correctly according to the number of certificates desired and the rule of redeeming them for that level of membership. It should also display the number of certificates redeemed and display the number of points remaining. This concrete method is to be inherited and used by all subclasses.

The second approach: Another way to code the concrete method redeemCertificates(integer noOfCertificatesRequested)is: it calculates the number of certificates that a member can redeem. If the member does not have enough points to redeem the requested number of certificates, it should return a 0 integer value to the caller statement. This means none has been redeemed. The caller statement receives the value and the test application should tell the user a sorry message and refuse to grant any certificates. If the redemption is possible, this method, redeemCertificates(integer noOfCertificatesRequested), should deduct the correct number of points from a member’s account correctly according to the number of certificates desired and the rule of redeeming them for that level of membership. It should return the number of certificates actually redeemed to the caller statement in the test application. Then the test application should also display the number of certificates redeemed and the number of points remaining. This concrete method is to be inherited and used by all subclasses. You can choose either approach and code the test application correspondingly to work with your choice of approach for writing this redeemCertificates(integer noOfCertificatesRequested) method.

Implement a subclass of Member called Gold. It should inherit all the attributes and methods from Member.

It should also have an additional boolean instance variable called annualPresentGiven. If a Gold member has not chosen to receive this annual present this year, this flag value for this Gold member is false. Otherwise, it is true.

As the class Gold has five instance variables, it should have a 5-parameter constructor. It inherits all concrete methods in Member and it should implement the abstract method addPoints(double purchaseValue) of class Member.

The class Gold should have two specific methods defined in it: (1) setAnnualPresentGiven(boolean value) and (2) getAnnualPresentGiven(). When a Gold member is either adding points or trying to redeem certificates (whether successful or not), the system checks whether this member has already taken his/her present this year via calling the method getAnnualPresentGiven(). If the boolean value returned is a false value, this means this member has not received the present this year. Then the system displays the message “Annual present not yet received.” If the value of this attribute is true, then the system displays “Annual present received.” Do not add an instance variable for holding the membership type of a particular member.

Follow a similar procedure for defining the subclass Silver with its own rules and values. Similarly, following a similar procedure for defining the subclass Basic with its own rules and values. However, they do NOT need the extra instance variable annualPresentGiven. They do NOT need the two methods:

(1) setAnnualPresentGiven(boolean value) and (2) getAnnualPresentGiven(). In order to perform all the required functions, the above classes may need other methods not described here. Write a Java application called JKLTest to use the above classes to perform the following. In method main of this application, create the following members with the following initial instance values:

Member ID Last Name First Name
20013 Jones David
20023 Shoemaker Lisa
20033 Miller James
20043 Keller Richard
20053 Brown Anna
Current Total
Points
4,000
1,000
12,890
50
3,729
Level of
Membership
Basic
Silver
Gold
Gold
Silver
Annual Present
Already Redeemed
n/a
n/a
false
true
n/a

Then the application lets a human user perform transactions: either a member accumulates more points or wants to redeem dining certificates until the human user chooses to quit. Repeated operations for the same member are possible. The main menu should be displayed as follows:

JKL Restaurant Membership Management Main Menu:
1. Add points to a member’s account
2. Redeem dining certificates for a member
3. Quit

Choice 1 Chosen:

If a user chooses 1, then the system:

  • Asks for member ID (you can assume that the member ID keyed in is a valid one).
  • Displays the member ID, member last name, member first name, his/her membership level, current total points of this member.
  • Asks for the purchase amount.
  • Update the total points of this member according to the level of membership by calling the appropriate method of the appropriate class.
  • Displays the new total number of points.
  • If the member is a Gold member, call the appropriate method to see if he/she has taken his/her annual present yet. If no, display “Annual present not yet received.” If yes, display “Annual present already received.”
  • Then the system displays the above main menu again.

Choice 2 Chosen: If a user chooses 2, then the system:

  • Asks for member ID (you can assume that the member ID keyed in is a valid one).
  • Displays the member ID, member last name, member first name, his/her membership level and current total points available, number of points needed per certificate, and the maximum number of dining certificates that he/she can redeem now.
  • Asks for the number of certificates this member would like to get (you can assume that the number keyed in is a positive integer).
  • Call the appropriate method of the appropriate class to do the following: see if this request is feasible.
    • If this request is feasible, then the system displays the result (no. of certificates awarded) and the newest available points remaining in the member’s account after this redemption.
    • If this request is not feasible, then the system displays the message that this cannot be done and tell him/her to try again with more points later. (Since the emphasis is inheritance and polymorphism here, we use an “all or nothing” redemption policy for simplicity.)
  • If the member is a Gold member, call the appropriate method to see if he/she has taken his/her annual present yet. If no, display “Annual present not yet received.” If yes, display “Annual present already received.”
  • Finally, the system displays the above main menu again.

Choice 3 Chosen: The system displays “Bye” and ends the execution. Hints:

  • Avoid using nextLine() for getting input from the user. This way this method gets the input is tricky. Use next() or nextDouble(), etc.
  • How to get the following: Rounded up nearest integer value of (purchase value *110%) double purchaseValue; double allPoints; int total; ... allPoints = purchaseValue * 1.10 ; total = (int) Math.ceil( allPoints );
  • How to store the information of all the members and get to a particular one needed? ... Member memberArray [ ] = new Member[100] ; int totalMember = 0; String inID = “”; ... Gold g1 = new Gold("29878", "James", "Miller", 12890); Silver s1 = new Silver("1314", "David", "King", 2999); ... memberArray[0] = g1 ; memberArray[1] = s1 ; ... totalMembers = 2 ; ... //get the next input member ID into String variable inID for (i = 0; i < totalMembers; i = i + 1) { if ( inID.equals(memberArray[i].getID()) ) //IDs matching { System.out.println("Member found, name = "+ i + " " + memberArray[i].getLastName()); ... } ... } ...
  • How to get the name of the membership class a particular member, e.g., memberArray[i], belongs to (Gold, Silver, or Basic)? memberArray[i].getClass().getName();
  • How to know whether to a member is a Gold member and determine to check the annual present status or not? boolean given; //boolean local variable in main to hold the // annual present status of a member . . . . if ( memberArray[i] instanceof Gold) { given = ((Gold) memberArray[i]).getAnnualPresentGiven(); . . . . }
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.