Question: (b) Consider a superclass Purchaseltem which models customer's purchases. This class has: -two private instance variables name (String) and unitPrice (double). - Overloaded constructors

(b) Consider a superclass Purchaseltem which models customer's purchases. This class has:

(b) Consider a superclass Purchaseltem which models customer's purchases. This class has: -two private instance variables name (String) and unitPrice (double). - Overloaded constructors to initialize the instance variables. - A default constructor to initialize name to "no item", and unitPrice to 0. use this() -A method getPrice that returns the unitPrice. -Accessor and mutator methods. - A toString method to return the name of the item followed by @ symbol, then the unitPrice. Consider two subclasses WeighedItem and CountedItem. WeighedItem has an additional instance variable weight (double) in Kg while CountedItem has an additional variable quantity (int) both private. - Write an appropriate constructor for each of the classes making use of the constructor of the superclass in defining those of the subclasses.

Step by Step Solution

3.40 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

class PurchaseItem private String name private double unitPrice Overloaded constructors public Purch... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!