Question: Given a class called Product, Product - id : String - price : double + Product() + Product(id : String, price : double) + getID()
Given a class called Product,
| Product |
|---|
| - id : String - price : double |
| + Product() + Product(id : String, price : double) + getID() : String + getPrice() : double + toString() : String |
Assume its toString method will return a string like this:
ID: id of this obj Price: $xxx.xx
Write a FreshProduce class which extends Product. All instance data members should be private and all constructors and methods should be public unless specified otherwise. This FreshProduce class should:
- Have an instance data member expirationDate of String, which records the expiration date of such a product in a string;
- a default constructor (0 parameters);
- A constructor with three parameters to initialize all data members;
- Override the toString method to return a string including id, price, and expiration date. You must take advantage of the toString from the parent class.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
