Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following problem description and write java code. A. Consider a superclass PurchaseItem which models customers purchases. This class has: 1. Two private instance

Consider the following problem description and write java code. A. Consider a superclass PurchaseItem which models customers purchases. This class has:

1. Two private instance variables name and unit price.

2. One constructor to initialize the instance variables.

3. A default constructor to initialize name to no item, and unit price to 0.

4. A method that returns the price.

5. A toString method to return the name of the item followed by @ symbol, then the unit price.

B. Consider two subclasses WeighedItem and CountedItem. WeighedItem has an additional instance variable weight while CountedItem has an additional variable quantity.

1. Write an appropriate constructor for each of the classes making use of the constructor of the superclass in defining those of the subclasses.

2. Override getPrice method that returns the price of the purchasedItem based on its unit price and weight (WeighedItem), or quantity (CountedItem). Make use of getPrice of the superclass

3. Override also toString method for each class making use of the toString method of the superclass in defining those of the subclasses.

4. toString should return something that can be printed on the receipt. For example Banana @ 3.00 1.37Kg 4.11 SR (in case of WeighedItem class) Pens @ 4.5 10 units 45 SR (in case of CountedItem class)

C. Write an application class where you construct objects from the two subclasses and print them on the screen.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

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

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

Were they made on a timely basis?

Answered: 1 week ago

Question

How do organizations reinforce the focus on nonprice attributes?

Answered: 1 week ago

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago