2
I have two classes, : Route and Costs.
Route :
public double getKmPercorrida() {
return kmPercorrida;
}
public void setKmPercorrida(double kmPercorrida) {
this.kmPercorrida = kmPercorrida;
}
public double getValorCombustivel() {
return valorCombustivel;
}
public void setValorCombustivel(double valorCombustivel) {
this.valorCombustivel = valorCombustivel;
}
public double getValorPedagio() {
return valorPedagio;
}
public void setValorPedagio(double valorPedagio) {
this.valorPedagio = valorPedagio;
}
public void cadastrarPercurso() {
setKmPercorrida(Double.parseDouble(JOptionPane.showInputDialog(null,"Digite os km percorridos : ","Km percorridos",JOptionPane.QUESTION_MESSAGE)));
setValorCombustivel(Double.parseDouble(JOptionPane.showInputDialog(null,"Digite o valor do combustivel : ","Combustivel",JOptionPane.QUESTION_MESSAGE)));
setValorPedagio(Double.parseDouble(JOptionPane.showInputDialog(null,"Digite o valor do pedágio : ","Pedágio",JOptionPane.QUESTION_MESSAGE)));
}
public void listarPercurso() {
JOptionPane.showMessageDialog(null,"Km percorridos : " + getKmPercorrida() +
"Valor do combustivel : " + getValorCombustivel() +
"Valor do pedágio : " + getValorPedagio());
}
Costs :
private double totalPercurso;
public double getTotalPercurso() {
return totalPercurso;
}
public void setTotalPercurso(double totalPercurso) {
this.totalPercurso = totalPercurso;
}
public String calcularViagem(Percurso [] p) {
return "";
}
In class Costs in the method calculate i have to receive an array of objects of type Route,and calculate the value of the trip, :
totalPercurso = (kmPercorrida * valorCombustivel) + valorPedagio
The variable totalPercurst will receive the variables of the Path object and calculate them all through the method in which it is.
But how can I do this ?
It was not clear. When it comes to object-oriented programming, we do not speak of "class variables" but "object variables". But I don’t see any Route object being used in your class "Costs".
– Pablo Almeida
I’m receiving it as an array of objects there in the calculator method,.
– Mondial
Again, it makes no sense to talk about "total class". Class is just a template to create objects. Besides, what do you mean by "total"? Total of what?
– Pablo Almeida
Total value together with other variables. I have to add all of them by the total variable.
– Mondial