Add a subclass named Finance_Period that will determine if a customer will pay interest or not. If the number of months to pay for the product is greater than three, the customer will pay 25% interest, else no interest applies. The maximum number of months to pay for the product is 12. Override the calculate_repayment () method by determining if the customer will pay interest or not and calculate the monthly repayment amount.
Create a class called Customer_Finance that contains the logic to test the two classes. Prompt the user for data for the first object where no interest applies and display the results; then prompt the user for data where interest is applicable and display the results.
public class FinancePeriod extends SomeClass {
@Override
public double calculateRepayment() {
double repayment = price / numberOfMonth;
if (numberOfMonth >= 3) {
repayment += (price * 0.25) / numberOfMonth;
}
return repayment;
}
}
import java.util.Scanner;
public class CustomerFinance {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
SomeClass someClass = new SomeClass();
FinancePeriod financePeriod = new FinancePeriod();
someClass.setPrice(Double.parseDouble(in.nextLine()));
someClass.setMonths(Integer.parseInt(in.nextLine()));
System.out.println(someClass.calculateRepayment());
financePeriod.setPrice(Double.parseDouble(in.nextLine()));
financePeriod.setMonths(Integer.parseInt(in.nextLine()));
System.out.println(financePeriod.calculateRepayment());
}
}
Comments
Leave a comment