Question

In: Computer Science

R.R.Word.file.R.R (Main Focus of Cheg-Study!) // this is the question below You will create specific customer...

R.R.Word.file.R.R

(Main Focus of Cheg-Study!)

// this is the question below

You will create specific customer classes with specialized behaviors for a regular subscription and platinum

subscription. This will focus on the concepts of inheritance and polymorphism.

Main objective. This will consist of four classes: Customer, RegularCustomer, PlatinumCustomer, and

Tester (or any name you’d prefer for the main method file). The Customer class will have a

name and type. The RegularCustomer and PlatinumCustomer classes will inherit both of these

fields from the Customer class. The PlatinumCustomer class will also have a discount field. The

methods for each of these classes will be the following:

Customer

* Customer (constructor)

* setName

* setType

* getName

* getType

* toString

RegularCustomer:

* RegularCustomer (constructor)

* toString

PlatinumCustomer

* PlatinumCustomer (constructor)

* setDiscount

* getDiscount

* toString

For the RegularCustomer and PlatinumCustomer constructors, the type of subscription should

be set to “regular” or “platinum". Each of these two constructors should also take

advantage of inheritance when setting the fields. Given a name of “David” and a type of

“regular”, the toString method for Customer and RegularCustomer should print the following:

David has a regular subscription.

The toString method for PlatinumCustomer should also include the discount. Assume a discount

of 7% for the following:

David has a platinum subscription. The current discount on purchases for this subscription is

7.0%.

In the Tester class, make a main method where you create a Customer reference variable. Ask

the user to input a type. If the user enters “regular” for the type, ask for the name and construct

a RegularCustomer object. If the user enters “platinum” for the type, ask for the name and a

discount and then construct a PlatinumCustomer object. Finally, print this created object

to the console.

Take note of one issue with this design. RegularCustomer and

PlatinumCustomer both inherit setType from Customer, but the user should never be able to

change the type for either of these subclasses. Implement an overriding setType for each of

these two subclasses that prevents the type from being changed.

The workflow of the main method should be similar to the following:

For a Regular Subscription;

run:

Please enter a type: regular

Please enter a name: David

David has a regular subscription.

Build successful (total time: 6 seconds)

For a Platinum Subscription;

Please enter a type: platinum

Please enter a name: David

Please enter a discount: 7

David has a platinum subscription.

The current discount on purchases for this subscription is 7.0%

Build successful (total time: 6 seconds)

(End of Work Cheg-Study!)

Solutions

Expert Solution

/******************************Customer.java******************/

/**
* The Class Customer.
*/
public class Customer {

   /** The name. */
   private String name;

   /** The type. */
   private String type;

   /**
   * Instantiates a new customer.
   */
   public Customer() {

       this.name = "";
       this.type = "";
   }

   /**
   * Instantiates a new customer.
   *
   * @param name the name
   * @param type the type
   */
   public Customer(String name, String type) {
       super();
       this.name = name;
       this.type = type;
   }

   /**
   * Gets the name.
   *
   * @return the name
   */
   public String getName() {
       return name;
   }

   /**
   * Sets the name.
   *
   * @param name the new name
   */
   public void setName(String name) {
       this.name = name;
   }

   /**
   * Gets the type.
   *
   * @return the type
   */
   public String getType() {
       return type;
   }

   /**
   * Sets the type.
   *
   * @param type the new type
   */
   public void setType(String type) {
       this.type = type;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return "Customer [name=" + name + ", type=" + type + "]";
   }

}
/************************RegularCustomer.java**********************/


/**
* The Class RegularCustomer.
*/
public class RegularCustomer extends Customer {

   /**
   * Instantiates a new regular customer.
   *
   * @param name the name
   * @param type the type
   */
   public RegularCustomer(String name, String type) {

       super(name, type);
   }

   /*
   * (non-Javadoc)
   *
   * @see Customer#toString()
   */
   @Override
   public String toString() {
       return getName() + " has a regular subscription.";
   }

}
/***********************************PlatinumCustomer.java***********************/


/**
* The Class PlatinumCustomer.
*/
public class PlatinumCustomer extends Customer {

   /** The discount. */
   private double discount;

   /**
   * Instantiates a new platinum customer.
   *
   * @param name the name
   * @param type the type
   */
   public PlatinumCustomer(String name, String type) {
       super(name, type);
   }

   /**
   * Instantiates a new platinum customer.
   *
   * @param name the name
   * @param type the type
   * @param discount the discount
   */
   public PlatinumCustomer(String name, String type, double discount) {
       super(name, type);
       this.discount = discount;
   }

   /**
   * Gets the discount.
   *
   * @return the discount
   */
   public double getDiscount() {
       return discount;
   }

   /**
   * Sets the discount.
   *
   * @param discount the new discount
   */
   public void setDiscount(double discount) {
       this.discount = discount;
   }

   /*
   * (non-Javadoc)
   *
   * @see Customer#toString()
   */
   @Override
   public String toString() {
       return getName() + " has a platinum subscription.\nThe current discount on purchases for this subscription is "
               + discount + "%";
   }

}
/***********************************Tester.java******************/

import java.util.Scanner;

/**
* The Class Tester.
*/
public class Tester {

   /**
   * The main method.
   *
   * @param args the arguments
   */
   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       System.out.print("Please enter a type: ");
       String type = scan.nextLine();
       System.out.print("Please enter a name: ");
       String name = scan.nextLine();
       Customer customer;
       if (type.equalsIgnoreCase("regular")) {

           customer = new RegularCustomer(name, type);
       } else {

           System.out.print("Please enter a discount: ");
           double discount = scan.nextDouble();
           customer = new PlatinumCustomer(name, type);
           ((PlatinumCustomer) customer).setDiscount(discount);
       }

       System.out.println(customer.toString());
       scan.close();
   }
}

/***************output******************/

Please enter a type: regular
Please enter a name: David
David has a regular subscription.

Please enter a type: platinum
Please enter a name: David
Please enter a discount: 7
David has a platinum subscription.
The current discount on purchases for this subscription is 7.0%

Please let me know if you have any doubt or modify the answer, Thanks :)


Related Solutions

What is johnson & johnson main focus
What is johnson & johnson main focus
Orginial Discussion Question: What would you want to study? If you could create a poll or...
Orginial Discussion Question: What would you want to study? If you could create a poll or survey, what would your topic be? Describe your population (the type of person you want), sample (n = ?), one to three questions you would ask, and how you would graph the results. Example: What would you desire to study? Many of my peers are present men and women online. he description of my sample would be a random sample that includes 30 prospective...
specific ways you can focus the nursing care of a child with a cardiac disorder to...
specific ways you can focus the nursing care of a child with a cardiac disorder to improve oxygenation, promote nutrition, prevent infection, provide post-op care, assist with coping, and provide education.  
First create the text file given below. Then complete the main that is given. There are...
First create the text file given below. Then complete the main that is given. There are comments to help you. An output is also given Create this text file: data1.txt -59 -33 34 0 69 24 -22 58 62 -36 5 45 -19 -73 62 -5 95 42 ` Create a project and a Main class and copy the Main class and method given below. First declare the array below the comments that tell you to declare it. Then there...
Companies are turning to Customer Relationship Management (CRM) to improve their customer focus. List and explain...
Companies are turning to Customer Relationship Management (CRM) to improve their customer focus. List and explain two of the major application components of a CRM system.
Please focus only on the variables I have provided as I have been very specific Question...
Please focus only on the variables I have provided as I have been very specific Question 1 The core elements of the Growth Employment and Redistribution (GEAR) strategy of the South African government in 1996, under the leadership of the then finance minister Trevor Manuel, were amongst other things:  budget reform to strengthen the redistributive thrust of expenditure  monetary policy to prevent a resurgence of inflation  a reduction in tariffs to contain input prices and facilitate industrial...
As companies shift from a product-centric focus to a customer-centric focus, a myth that almost all...
As companies shift from a product-centric focus to a customer-centric focus, a myth that almost all current customers are profitable needs to be replaced with the truth. Some high-demanding customers may indeed be unprofitable! Here’s the basic problem. With accounting’s traditional product gross profit margin reporting, managers can’t see the more important and relevant “bottom half” of the total income statement picture–all the profit margin layers that exist and should be reported from customer-related MSDA expenses. Based on your new...
Study the diagrams below and answer the following question:
 Study the diagrams below and answer the following question: 3. Which of the following statements are correct? a. Diagram A illustrates that investment spending takes place when firms increase their spending on capital goods. b. Diagram A illustrates that in the event of a rise in the interest rate an upward movement will take place along the investment curve. c. Diagram B illustrates that an increase the level of output and income will cause a rightward shift of the investment curve. d. Diagram A illustrates...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
International Political Economics - Question What is the study of IPE and what are the main...
International Political Economics - Question What is the study of IPE and what are the main approaches of IPE. Explain their main focuses and characteristics.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT