Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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: -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
Step: 1
class PurchaseItem private String name private double unitPrice Overloaded constructors public Purch...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