Answered step by step
Verified Expert Solution
Link Copied!

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

image

(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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Guide To Java A Concise Introduction To Programming

Authors: James T. Streib, Takako Soma

2nd Edition

3031228413, 978-3031228414

More Books

Students also viewed these Programming questions