Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For your first lab assignment, you will build a simple application for use by a local retail store. Your program should have the following classes:
For your first lab assignment, you will build a simple application for use by a local retail store. Your program should have the following classes:
- Item: Represents an item a customer might buy at the store. It should have two fields: a String for the item description and a double for the price. This class should also override the toString method in a nicely formatted way.
- Customer: Represents a customer at the store. It should have a field for the customer's name and an array of 5 indexes to hold Item objects. Include the following methods:
- makePurchase: accepts a String and a double as parameters. Create a new Item object and add it to the internal array. Note: If the internal array is full, simply print a message that the customer can no longer make purchases. We will explore better options for this scenario in the future.
- toString: Override this method to print the customer's name and every purchase they have made (make sure to make use of the Item toString method). Since you may be working with a partially filled array (if the customer has made less than 5 purchases), ignore the logically empty indexes.
- PreferredCustomer: Represents a customer at the store who gets a discount on each discount. This class should be a subclass of Customer. Its only unique characteristic is it should override the makePurchase method to still accept a product description and price, but it should apply a 10% discount before calling the superclass version of the method.
Once you have built these three classes, build a driver program to test them. Try creating a Customer and a PreferredCustomer and testing each of the methods you implemented.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started