Qual Padrão de Projeto foi implementado nesse código?
Código fonte em Java para as questões 34 e 35.
package com.example. demo;
public class MyCalc {
public static void main(String[] args) {
double amount = 1000;
double intRate = 2;
int period = 12;
CalcSrv c = new CalcSrv(new CalcLC());
double fv = c.fValue (amount, intRate, period);
System.out.printf("VF of LC:%.2\n", fv);
c = new CalcSrv (new CalcCDB());
fv = c.fValue(amount,intRate, period);
System.out.printf("VE of CDB:%.2f", fv);
}
private static class CalcSrv {
private CalcFV calcsrv;
public CalcSrv(CalcFV calcsrv) {
this.calcsryv = calesrv;
}
public double fvalue(double amount, double intRate, int period) {
amount = amount + calcsrv.calc(amount, intRate, period);
return amount;
}
}
interface CalcFV {
double calc(double amount, double intRate, int period);
}
private static class CalcLC implements CalcFV{
@Override
public double calc(double amount, double intRate, int period)
return (amount * Math.pow(1 + intRate/100, period)) - amount;
}
}
private static class CalcCDB implements CalcFV{
@Override
public double calc(double amount, double intRate, int period){
double fv = amount * Math.pow(1 + intRate/100, period);
if (period >12)
return (fv - amount) * 0.85;
return (fv - amount) * 0.78;
}
}
}
Qual Padrão de Projeto foi implementado nesse código?