I have 2 Classes, which are: Path and Costs .
Path :
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 the Costs class in the Calculate method, I have to get an array of objects of type Route and calculate the value of the trip,
totalPercurso = (kmPercorrida * valorCombustivel) + valorPedagio
The variable totalPower will receive the variables of the Path object and calculate all of them through the method it is in.
But how can I do this?