✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.
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)