logo

Crowdly

Browser

Додати до Chrome

3.1  Design a class hierarchy to model different types of trade tariffs. Your im...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

3.1 Design a class hierarchy to model different types of trade tariffs. Your implementation should demonstrate understanding of inheritance and polymorphism.

Class Design

·         Create an abstract base class Tariff with these properties:

name (String)

·         rate (double - represents percentage rate)

·         effectiveDate (String)

·         and one abstract method: double calculateDuty(double productValue)

Create three concrete subclasses that extend Tariff:

·         SteelTariff (adds property: steelType String)

·         AluminumTariff (adds property: countryOfOrigin String)

·         ChinaTariff (adds property: productCategory String)

Method Implementation

·         Implement the calculateDuty() method differently for each subclass:

For SteelTariff:

·         Base calculation is productValue * rate

·         Add 5% surcharge if steelType is "stainless"

·         For AluminumTariff:

·         Base calculation is productValue * rate

·         Add 10% surcharge if countryOfOrigin is "Canada"

For ChinaTariff:

·         Flat $500 fee if productCategory is "electronics"

·         Otherwise productValue * rate

Demonstration

Create a main method that:

·         Creates an array of Tariff objects containing one instance of each subclass

·         Initializes each with appropriate values.

·         Iterates through the array, calling calculateDuty() for a sample product value of $10,000

·         Prints the calculated duty for each tariff

(25 MARKS)

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на learning.richfield.ac.za?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome