Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA I need help completing this program. Preferred Customer Program 20 Points Your Task In this program you will demonstrate the use of inheritance by

JAVA

I need help completing this program.

image text in transcribed

image text in transcribed

image text in transcribed

Preferred Customer Program 20 Points Your Task In this program you will demonstrate the use of inheritance by coding Customer (superclass) and PreferredCustomer (subclass) classes. Additional topics include: overriding toString(, calling the superclass constructor from the subclass, use of an ArrayList to store both Customer and PreferredCustomer objects, and polymorphism. Code the following two classes: Customer (superclass) and PreferredCustomer (subclass, extends Customer). See next page for detailed specs. ustomer Private instance variables: - A String for the customerID - A String for the customerName - A String for the customer's email address - A boolean called isPreferred, which indicates whether the customer is a preferred customer or not Methods: Iwo constructors: 1) An empty/default ctor, 2) a 4-parameter ctor to initialize each of the four instance variables Gets and sets for all instance variables. You may use the refactor > encapsulate method to easily generate these. Override toString method to produce the following line of sample data: 1234 Dasn Datitueci patitueeifenainevalley-edu No The customer ID is left-aligned (use minus aign) in a field 8 characters wide. The customer name is leftaligned in a field 25 characters wide. The amail address is left-aligned in a field 35 characters wide. Use an if else to convert the boolean value to "yes" or "no" before displaying it left-aligmed in a field 10 characters wide. PreferredCustomer - eutends Customer Private instance variables: - A double for the discount rate - An int representing the customer's rewards points balance Methods: Iwo constructors: 1) An empty/default ctor, 2) a six-parameter ctor which accepts arguments for all four superclass instance variables as well as the two variables in this subclass. Your constructor will explicitly call the superclass constructor and pass values for id, name, email, and preferred status to the super. The constructor will also initialize the remaining two instance variables (discount and rewards points) here in the subclass. Gets and sets for all instance variables. Override toString method to produce the following sample data: Note that the first line of output can be accomplished by calling super.toString0. You can then append a newline and a tab "nt" and constract the second line of output using hardcoded strings and the private instance variable values. In your main class/method, create an ArrayList of type Customer and populate the list with a mixture of regular customers and preferred customers. Here is some sample code (you can make up new customer data or use these below): ArrayListecustomers al1Cugcomers - new ArrayLister (): a11cuacomers, add(new Cuaconex("1234", "Dawn pacitunein, "pacicuccigacra1hova11ey, ndu", falae)); Lastly, loop through your ArrayList to produce the following output. If you coded your toString() methods properly, your output should fall into place easily. (Note that this is a demonstration of polymorphism.)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MFDBS 91 3rd Symposium On Mathematical Fundamentals Of Database And Knowledge Base Systems Rostock Germany May 6 9 1991

Authors: Bernhard Thalheim ,Janos Demetrovics ,Hans-Detlef Gerhardt

1991st Edition

3540540091, 978-3540540090

More Books

Students also viewed these Databases questions