-2
I did an interview test, but I didn’t pass.
I would like someone to help me correct this exercise;
Create a Main class that receives an initial value from the user, and simulate month by month how much profit the user will receive, considering 2 investments:
- Investing with 0.35% monthly interest
- Investimentosemir with 0.3% monthly interest
Simulate the profit achieved in 36 months as shown below:
Parent or Superclass class;
public class Investimentos {
public double valorIncial;
public double jurosMensais;
public Investimentos(){
}
public Investimentos(double valor, double juros){
this.valorIncial = valor;
this.jurosMensais = juros;
}
double soma = 0;
public void calcularLucro(int meses) {
double montante = valorIncial * Math.pow((1 + jurosMensais), meses);
double lucro = montante - valorIncial;
for(int i = 1; i < meses; i++){
soma = soma + lucro;
System.out.printf("Mês: " + i + " | Investimento com IR: %.2f%n", soma);
//System.out.printf("Investimento classe Pai: %.2f ", lucro);
}
}
}
DAUGHTER OR SUB-CLASS.
public class InvestimentoComIR extends Investimentos {
public InvestimentoComIR(){
}
public InvestimentoComIR(double valor, double juros) {
super(valor, juros);
}
double descontoIR;
double valorFinal;
double soma = 0;
@Override
public void calcularLucro(int meses) {
//super.calcularLucro(meses);
double resultado = valorIncial * Math.pow((1 + jurosMensais), meses);
double resultado1 = resultado - valorIncial;
for(int i = 1; i < meses; i++){
if (meses < 6) {
descontoIR = resultado1 * 0.225;
valorFinal = resultado1 - descontoIR;
System.out.printf("Mês: " + i + " | Investimento com IR: %.2f%n", valorFinal);
} else if (meses >= 6 && meses < 12) {
descontoIR = resultado1 * 0.20;
valorFinal = resultado1 - descontoIR;
System.out.printf("Mês: " + i + " | Investimento com IR: %.2f%n", valorFinal);
} else if (meses >= 12 && meses < 24){
descontoIR = resultado1 * 0.175;
valorFinal = resultado1 - descontoIR;
System.out.printf("Mês: " + i + " | Investimento com IR: %.2f%n", valorFinal);
} else{
descontoIR = resultado1 * 0.15;
valorFinal = resultado1 - descontoIR;
soma = soma + resultado1;
System.out.printf("Mês: " + i + " | Investimento com IR: %.2f%n", soma);
}
}
}
}
Misinterpretation, the exercise asks Create a Main class that receives an initial value from the user, and simulate month by month how much profit the user will receive, considering 2 investments:, class was not requested
Investimentos
,InvestimentoComIR
it was just a classMain
that reads fromstdin
user input and then make an interest calculation with no IR rate.– Augusto Vasques
I did the Main class, but I would like to know if my formula is correct, because I put the months and interest that ask in the announced, but month by month the value does not match. However, when I perform the 1 exercise (this is the second one) of the right.
– WeslleySP