Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions