Question

Please explain each line of code, all code will be in Java. Thank you JKL Restaurant...

Please explain each line of code, all code will be in Java. Thank you

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 of (purchase value *110%)

Rounded up nearest integer value of (purchase value *105%)

Rounded up nearest integer value 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 Memberunder which there are three concrete classes: Gold, Silver, and Basic.  

Private instance variables in class Memberinclude

  1. a String memberID
  2. a String lastName
  3. a String firstName
  4. an integer currentTotalPoints

Private static (class) variable in class Member: noOfPointsPerCert.  Please initialize it to 300 when you declare this private attribute:  

            private static int noOfPointsPerCert = 300;

This static variable will also be inherited by each subclass.

Do notdeclare an instance variable for holding the membership type of a particular member.

----------------------------------------------------------------------------------------------------------------------

The class Membershould have a 4-parameter constructor that accepts four input parameter values for each of the instance variables above.

The class Membershould have a set  method and a get  method for each of the instance variables above. It should also have a static setmethod and a static getmethod for the static variable noOfPointsPerCert.  These are all concrete methods. These are to be inherited and used by all those subclasses.

The class Membershould have an abstractmethod 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 concretemethod redeemCertificates(integer noOfCertificatesRequested).  The way to code the concrete method 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.

------------------------------------------------------------------------------------------------------------------------

Implement a subclass of  Member calledGold.  It should inherit all the attributes and methods from Member.  It should also have an additional boolean instance variable called annualPresentGiven. If a Goldmember has not chosen to receive this annual present this year, this flag value for this Goldmember is false.  Otherwise, it is true.

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

The class Gold should have two specific instance-level methods defined in it:

(1) setAnnualPresentGiven(boolean value)and (2) getAnnualPresentGiven(). When a Goldmember 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 (driver application) displays the message “Annual present not yet received.” If the value of this attribute is true, then the system (driver application) displays “Annual present received.”

Do notadd 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().

Write a Java application called JKLTestto use the above classes to perform the following.  In method mainof this application, create the following members with the following initial instance values:

Member ID

Last Name

First Name

Current Total Points

Level of Membership

Annual Present Already Redeemed

20013

Jones

David

    4,000

Basic

n/a

20023

Shoemaker

Lisa

    1,000

Silver

n/a

20033

Miller

James

  12,890

Gold

false

20043

Keller

Richard

         50

Gold

true

20053

Brown

Anna

    3,729

Silver

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:

(1)        Asks for member ID (you can assume that the member ID keyed in is a valid one).

(2)        Displays the member ID, member last name, member first name, his/her membership level, current total points of this member.

(3)        Asks for the purchase amount.

(4)        Update the total points of this member according to the level of membership by calling the appropriate method of the appropriate class.

(5)        Displays the new total number of points.

(6)        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.”

(7)        Then the system displays the above main menu again.

Choice 2 Chosen:

If a user chooses 2, then the system:

(1)        Asks for member ID (you can assume that the member ID keyed in is a valid one).

(2)        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.

(3)        Asks for the number of certificates this member would like to get (you can assume that the number keyed in is a positive integer).

(4)        Call the appropriate method of the appropriate class to do the following: see if this request is feasible.

(a)        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.

(b)        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.)

(5)        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.”

(6)        Finally, the system displays the above main menu again.

Choice 3 Chosen:

The system displays “Bye” and ends the execution.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Member.java

public abstract class Member {

      

       private String memberID;

       private String lastName;

       private String firstName;

       private int currentTotalPoints;

       private static int noOfPointsPerCert = 300;

      

       public Member(String memberID, String lastName, String firstName, int currentTotalPoints)

       {

             this.memberID = memberID;

             this.lastName = lastName;

             this.firstName = firstName;

             this.currentTotalPoints = currentTotalPoints;

       }

      

       public void setMemberID(String memberID)

       {

             this.memberID = memberID;

       }

      

       public String getMemberID()

       {

             return memberID;

       }

      

       public void setFirstName(String firstName)

       {

             this.firstName = firstName;

       }

      

       public String getFirstName()

       {

             return firstName;

       }

      

       public void setLastName(String lastName)

       {

             this.lastName = lastName;

       }

      

       public String getLastName()

       {

             return lastName;

       }

      

       public void setCurrentTotalPoints(int currentTotalPoints)

       {

             this.currentTotalPoints = currentTotalPoints;

       }

      

       public int getCurrentTotalPoints()

       {

             return currentTotalPoints;

       }

      

       public static void setNoOfPointsPerCert(int pointsPerCert)

       {

             noOfPointsPerCert = pointsPerCert;

       }

      

       public static int getNoOfPointsPerCert()

       {

             return noOfPointsPerCert;

       }

      

       public abstract void addPoints(double purchaseValue);

      

       public int redeemCertificates(int noOfCertificatesRequested)

       {

             int numCertificates = (int)(currentTotalPoints/noOfPointsPerCert);

             if(numCertificates >= noOfCertificatesRequested)

             {

                    currentTotalPoints -= (noOfCertificatesRequested*noOfPointsPerCert);

                    return noOfCertificatesRequested;

             }else

                    return 0;   

       }

}

//end of Member.java

//Gold.java

public class Gold extends Member{

      

       private boolean annualPresentGiven;

      

       public Gold(String memberID, String lastName, String firstName, int currentTotalPoints, boolean annualPresentGiven) {

             super(memberID, lastName, firstName, currentTotalPoints);

             this.annualPresentGiven = annualPresentGiven;

       }

      

       public void setAnnualPresentGiven(boolean value)

       {

             this.annualPresentGiven = value;

       }

      

       public boolean getAnnualPresentGiven()

       {

             return annualPresentGiven;

       }

       @Override

       public void addPoints(double purchaseValue) {

            

              this.setCurrentTotalPoints(this.getCurrentTotalPoints()+((int)Math.round(purchaseValue*1.1)));

       }

      

      

}

//end of Gold.java

//Silver.java

public class Silver extends Member{

      

       public Silver(String memberID, String lastName, String firstName, int currentTotalPoints) {

             super(memberID, lastName, firstName, currentTotalPoints);

       }

       @Override

       public void addPoints(double purchaseValue) {

              this.setCurrentTotalPoints(this.getCurrentTotalPoints()+((int)Math.round(purchaseValue*1.05)));

            

       }

      

}

//end of Silver.java

//Basic.java

public class Basic extends Member{

       public Basic(String memberID, String lastName, String firstName, int currentTotalPoints) {

             super(memberID, lastName, firstName, currentTotalPoints);

       }

       @Override

       public void addPoints(double purchaseValue) {

              this.setCurrentTotalPoints(this.getCurrentTotalPoints()+((int)Math.round(purchaseValue)));

            

       }

      

}

//end of Basic.java

//JKLTestto.java

import java.util.Scanner;

public class JKLTestto {

       // method to get the index of the member in the members array, -1 if memberID not present

       public static int getMemberIndex(Member members[], String memberID)

       {

             for(int i=0;i<members.length;i++)

             {

                    if(memberID.equalsIgnoreCase(members[i].getMemberID()))

                           return i;

             }

            

             return -1;

       }

      

       public static void main(String[] args) {

             Member members[] = new Member[5];

             members[0] = new Basic("20013","Jones","David",4000);

             members[1] = new Silver("20023","Shoemaker","Lisa",1000);

             members[2] = new Gold("20033","Miller","James",12890,false);

             members[3] = new Gold("20043","Keller","Richard",50,true);

             members[4] = new Silver("20053","Brown","Anna",3729);

             Scanner scan = new Scanner(System.in);

             int choice, index;

             String memberId;

             double purchaseValue;

             int numCertificates;

             // loop to continue till the user wants

             do {

                    System.out.println("\nJKL Restaurant Membership Management Menu:");

                    System.out.println("1. Add points to a member’s account");

                    System.out.println("2. Redeem dining certificates for a member");

                    System.out.println("3. Quit");

                    System.out.print("Enter your choice(1/2/3) : ");

                    choice = scan.nextInt();

                   

                    while(choice < 1 || choice > 3)

                    {

                           System.out.println("Invalid choice");

                           System.out.print("Enter your choice(1/2/3) : ");

                           choice = scan.nextInt();

                    }

                   

                    scan.nextLine();

                   

                    switch(choice)

                    {

                    // Add points to the member's account

                    case 1:

                           System.out.print("Enter your memberID : ");

                           memberId = scan.nextLine();

                           index = getMemberIndex(members,memberId);

                           if(index != -1)

                           {

                                 System.out.print("Member ID : "+memberId+"\nLastName : "+members[index].getLastName()+"\nFirstName : "+members[index].getFirstName()+"\nMembership Level : ");

                                 if(members[index] instanceof Gold)

                                        System.out.print("Gold");

                                 else if(members[index] instanceof Silver)

                                        System.out.print("Silver");

                                 else

                                        System.out.print("Basic");

                                 System.out.println("\nCurrent points : "+members[index].getCurrentTotalPoints());

                                

                                 System.out.print("Enter the purchase amount : ");

                                 purchaseValue = scan.nextDouble();

                                 scan.nextLine();

                                 members[index].addPoints(purchaseValue);

                                 System.out.println("Updated points : "+members[index].getCurrentTotalPoints());

                                 if(members[index] instanceof Gold)

                                 {

                                        if(((Gold)members[index]).getAnnualPresentGiven())

                                               System.out.println("Annual present received");

                                        else

                                               System.out.println("Annual present not yet received.");

                                 }

                           }else

                                 System.out.println("No member with "+memberId+" exists.");

                           break;

                          

                    case 2:

                           // Redeem dining certificates for a member

                           System.out.print("Enter your memberID : ");

                           memberId = scan.nextLine();

                           index = getMemberIndex(members,memberId);

                           if(index != -1)

                           {

                                 System.out.print("Member ID : "+memberId+"\nLastName : "+members[index].getLastName()+"\nFirstName : "+members[index].getFirstName()+"\nMembership Level : ");

                                 if(members[index] instanceof Gold)

                                        System.out.print("Gold");

                                 else if(members[index] instanceof Silver)

                                        System.out.print("Silver");

                                 else

                                        System.out.print("Basic");

                                 System.out.println("\nCurrent points : "+members[index].getCurrentTotalPoints()+"\nNumber of points needed per certificate : "+Member.getNoOfPointsPerCert());

                                 System.out.println("Maximum number of dining certificates that can be redeemed : "+(int)(members[index].getCurrentTotalPoints()/Member.getNoOfPointsPerCert()));

                                

                                 System.out.print("Enter the number of certificates this member would like to get : ");

                                 numCertificates = scan.nextInt();

                                 int result = members[index].redeemCertificates(numCertificates);

                                 if(result == 0)

                                 {

                                        System.out.println("Redemption of "+numCertificates+" certificates not possible. Please try again with more points");

                                 }else

                                 {

                                        System.out.println(numCertificates+" certificates redeemed. Remaining Points : "+members[index].getCurrentTotalPoints());

                                 }

                                

                                 if(members[index] instanceof Gold)

                                 {

                                        if(((Gold)members[index]).getAnnualPresentGiven())

                                               System.out.println("Annual present received");

                                        else

                                               System.out.println("Annual present not yet received.");

                                 }

                           }else

                                 System.out.println("No member with "+memberId+" exists.");

                           break;

                    case 3:

                           // Exit

                           break;

                    }

                   

             }while(choice != 3);

             System.out.println("Bye");

             scan.close();

       }

}

//end of JKLTestto.java

Output:

Add a comment
Know the answer?
Add Answer to:
Please explain each line of code, all code will be in Java. Thank you JKL Restaurant...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Program Please help me with this. It should be pretty basic and easy but I...

    Java Program Please help me with this. It should be pretty basic and easy but I am struggling with it. Thank you Create a superclass called VacationInstance Variables destination - String budget - double Constructors - default and parameterized to set all instance variables Access and mutator methods budgetBalance method - returns the amount the vacation is under or over budget. Under budget is a positive number and over budget is a negative number. This method will be overwritten in...

  • Question 1: Suppose you have to develop an information system for a popular restaurant chain. Points...

    Question 1: Suppose you have to develop an information system for a popular restaurant chain. Points are added the customer depending on the purchases made. The customers are grouped based on number of points a. Create a class called Customer that includes attributes: id, name, points and group. b. Include set methods for id, and name attributes (id should only accept numbers and name should only accept alphabets) c. Include a constructor with parameters id and name. d. Include a...

  • JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH...

    JAVA... QUESTION 3 IS A CONTINOUS TO Q2 CAN YOU SEND THE CODE SEPARATELY FOR EACH Q , I BE SO THANKFUL Q2. Implement a program to store the applicant’s information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented...

  • All code will be in Java, and there will be TWO source code. I. Write the...

    All code will be in Java, and there will be TWO source code. I. Write the class  MailOrder to provide the following functions: At this point of the class, since we have not gone through object-oriented programming and method calling in detail yet, the basic requirement in this homework is process-oriented programming with all the code inside method processOrderof this class. Inside method processOrder, we still follow the principles of structured programming.   Set up one one-dimensional array for each field: product...

  • please help me with this python code thank you 1. Write a Student class that stores...

    please help me with this python code thank you 1. Write a Student class that stores information for a Rutgers student. The class should include the following instance variables: (10 points) o id, an integer identifier for the student o lastName, a string for the student&#39;s last name o credits, an integer representing the number of course-credits the student has earned o courseLoad, an integer representing the current number of credits in progress Write the following methods for your Student...

  • In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class....

    In JAVA Algorithm Workbench 1. Write the first line of the definition for a Poodle class. The class should extend the Dog class. 2. Look at the following code, which is the first line of a class definition: public class Tiger extends Felis In what order will the class constructors execute? 3. Write the statement that calls a superclass constructor and passes the arguments x, y, and z. 4. A superclass has the following method: public void setValue(int v) value...

  • Please use public class for java. Thank you. 1. (10 points) Write a method that computes...

    Please use public class for java. Thank you. 1. (10 points) Write a method that computes future investment value at a given interest rate for a specified number of years. The future investment is determined using the formula futurelnvestmentValue numberOfYears 12 investmentAmount X ( monthlyInterestRate) Use the following method header: public static double futurelnvestmentValue( double investmentAmount, double monthlyInterestRate, int years) For example, futureInvestmentValue 10000, 0.05/12, 5) returns 12833.59. Write a test program that prompts the user to enter the investment...

  • (To be written in Java code) Create a class named CollegeCourse that includes the following data...

    (To be written in Java code) Create a class named CollegeCourse that includes the following data fields: dept (String) - holds the department (for example, ENG) id (int) - the course number (for example, 101) credits (double) - the credits (for example, 3) price (double) - the fee for the course (for example, $360). All of the fields are required as arguments to the constructor, except for the fee, which is calculated at $120 per credit hour. Include a display()...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT