0
I’m doing a small project on expense control, I’m with a class called Expense which is an abstract class, and other classes called Transport,Feeding and Daily will inherit from it the total value of expenses and two other methods. And I also have a separate class called Expense manager with a method that will pass the class by parameter Expense and take the total value of all other classes, and sum the total value within a variable called total expenses. The problem is that when I calculate one of the three classes that are inheriting, Expense will go to all, being that I wanted to separate, the total value of each class and then the total sum of the three classes.
Class Expense manager :
public class GerenciadorDespesas {
private int qtdeAlimentacao;
private int qtdeTransporte;
private int qtdeDiaria;
private double totalAlimentacao;
private double totalTransporte;
private double totalDiaria;
private double totalDespesas;
public int getQtdeAlimentacao() {
return qtdeAlimentacao;
}
public void setQtdeAlimentacao(int qtdeAlimentacao) {
this.qtdeAlimentacao = qtdeAlimentacao;
}
public int getQtdeTransporte() {
return qtdeTransporte;
}
public void setQtdeTransporte(int qtdeTransporte) {
this.qtdeTransporte = qtdeTransporte;
}
public int getQtdeDiaria() {
return qtdeDiaria;
}
public void setQtdeDiaria(int qtdeDiaria) {
this.qtdeDiaria = qtdeDiaria;
}
public double getTotalAlimentacao() {
return totalAlimentacao;
}
public void setTotalAlimentacao(double totalAlimentacao) {
this.totalAlimentacao = totalAlimentacao;
}
public double getTotalTransporte() {
return totalTransporte;
}
public void setTotalTransporte(double totalTransporte) {
this.totalTransporte = totalTransporte;
}
public double getTotalDiaria() {
return totalDiaria;
}
public void setTotalDiaria(double totalDiaria) {
this.totalDiaria = totalDiaria;
}
public double getTotalDespesas() {
return totalDespesas;
}
public void setTotalDespesas(double totalDespesas) {
this.totalDespesas = totalDespesas;
}
public void analisarDespesas(Despesa despesa) {
setTotalAlimentacao(despesa.getValorTotal());
setTotalTransporte(despesa.getValorTotal());
setTotalDiaria(despesa.getValorTotal());
setTotalDespesas(getTotalAlimentacao() + getTotalTransporte() +
getTotalDiaria());
}
}
Expense Class :
import javax.swing.JOptionPane;
public abstract class Despesa {
private String descricao;
private double valorTotal;
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public double getValorTotal() {
return valorTotal;
}
public void setValorTotal(double valorTotal) {
this.valorTotal = valorTotal;
}
public void cadastrarDespesa() {
setValorTotal(0);
setDescricao(JOptionPane.showInputDialog("Digite a descrição da Despesa : "));
}
public abstract void calcularDespesa();
public abstract void listarDespesa();
}
Excuse me, if the explanation of the problem has gotten too big or if the code has gotten too big, please,.
Actually, you can’t answer with just this. You have less information. But something tells me I shouldn’t be using inheritance.
– Maniero
The other three classes only have the registration of variables and their listing and the calculation nothing else.Now about the inheritance,worked in my other project,I do not know why this one is not working.
– Falion
Ah, yes if it works on a project, it will work on everyone. I don’t even know what it means worked. You mean you compiled? OOP is not this.
– Maniero
When I said this I meant that it worked with practically the same code and with a class that was also a manager that had the same function as this one. If you want to take the irony and sarcasm side that’s fine, but I didn’t insult you in any way to come do this.
– Falion