Question: Write an inheritance hierarchy that enables polymorphism for the classes defined in parts 1, 2 and 3. Part #1 (20 points) Product (an abstract class)

Write an inheritance hierarchy that enables polymorphism for the classes defined in parts 1, 2 and 3.

Part #1 (20 points)

Product (an abstract class) (1 point)

Attributes

  • code: a String of characters (1 point)
  • name: a String of characters (1 point)
  • basicPrice: a double value (1 point)
  • count: to count the number of all products (1 point)

Methods

  • Default Constructor (2 points)
  • Constructor (3 points)
  • set and get methods (7 points)
  • toString: returns information about a Product (2 points)
  • calculatePrice: an abstract method (1 point)

Part #2 (20 points)

LocalProduct (a Product) (2 points)

Attributes

  • supplierName: a String of characters (1 point)
  • type: an integer value that can be set to 1 or 2 only (1 point)

Methods

  • Default Constructor (2 points)
  • Constructor (4 points)
  • set and get methods (4 points)
  • toString: returns information about a LocalProduct (3 points)
  • calculatePrice: returns the price of a LocalProduct by adding to the basic price: (3 points)

5% if type is equal to 1

8% if type is equal to 2

Part #3 (20 points)

ImportedProduct (a Product) (2 points)

Attributes

  • countryOfOrigin: a String of characters (1 point)
  • tariff: a double value (1 point)

Methods

  • Default Constructor (2 points)
  • Constructor (4 points)
  • set and get methods (4 points)
  • toString: returns information about an ImportedProduct (3 points)
  • calculatePrice: returns the price of an ImportedProduct by adding to the basic price: (3 points)

5% of basic price if country of origin is USA

Amount of tariff

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!