Write two complete classes (FeeStructur2020 & FreeStructur2021) that implements FeeStructure interface
Suppose:
FeeStructure2020 calculates the fee based on the following
FeeStructure2021 calculates the fee based on the following
interface FeeStructure {
double calculateFee(int creditHour, String type);
double calculateFee(int creditHour, String type, int discountPercent);
}
class FeeStructur2020 implements FeeStructure {
/**
* PKR 4,100 per creditHour when type is set to "theory" PKR 12,250 per
* creditHour when type is set to "lab"
*/
@Override
public double calculateFee(int creditHour, String type) {
if (type.compareToIgnoreCase("theory") == 0) {
return 4100 * creditHour;
}
if (type.compareToIgnoreCase("lab") == 0) {
return 12250 * creditHour;
}
return 0;
}
@Override
public double calculateFee(int creditHour, String type, int discountPercent) {
double fee = calculateFee(creditHour, type);
return fee - ((fee * (double) discountPercent) / 100.0);
}
}
class FreeStructur2021 implements FeeStructure {
/**
* PKR 4,600 per creditHour when type is set to "theory" PKR 13,750 per
* creditHour when type is set to "lab"
*/
@Override
public double calculateFee(int creditHour, String type) {
if (type.compareToIgnoreCase("theory") == 0) {
return 4600 * creditHour;
}
if (type.compareToIgnoreCase("lab") == 0) {
return 13750 * creditHour;
}
return 0;
}
@Override
public double calculateFee(int creditHour, String type, int discountPercent) {
double fee = calculateFee(creditHour, type);
return fee - ((fee * (double) discountPercent) / 100.0);
}
}
class App {
public static void main(String[] args) {
FeeStructur2020 FeeStructur2020 = new FeeStructur2020();
FreeStructur2021 FreeStructur2021 = new FreeStructur2021();
System.out.println("FeeStructur2020: " + FeeStructur2020.calculateFee(10, "theory"));
System.out.println("FeeStructur2020 discountPercent: " + FeeStructur2020.calculateFee(25, "lab", 10));
System.out.println("FreeStructur2021: " + FreeStructur2021.calculateFee(20, "lab"));
System.out.println("FreeStructur2021 discountPercent: " + FreeStructur2021.calculateFee(5, "theory", 20));
}
}
Comments
Leave a comment