-1
I am trying to make a code but error in the array. If someone can give me a light.
Master code:
import java.util.Scanner;
public class Tanque {
int valor;
private int kmTotal = 0;
private int gasolinaTotal = 0;
Scanner sc = new Scanner(System.in);
public int kmLitro(final int Quilometros, final int Litros) {
return Quilometros / Litros;
}
public int getValor() {
return valor;
}
public void setValor(int valor) {
this.valor = valor;
}
public int getKmTotal() {
return kmTotal;
}
public void setKmTotal(int kmTotal) {
this.kmTotal = kmTotal;
}
public int getGasolinaTotal() {
return gasolinaTotal;
}
public void setGasolinaTotal(int gasolinaTotal) {
this.gasolinaTotal = gasolinaTotal;
}
public int tanques[][] = new int [2][valor]; {
for (int i=0;i<=valor-1;i++) {
System.out.println("Digite os quilometros dirigidos do "+(i+1)+"° tanque.");
tanques[0][i] = sc.nextInt();
sc.nextLine();
kmTotal =+ tanques[0][i];
System.out.println("Digite os litros de gasolina gastos do "+(i+1)+"° tanque.");
tanques[1][i] = sc.nextInt();
sc.nextLine();
gasolinaTotal =+ tanques[1][i];
}
}
}
And the test is :
public class TanqueTeste {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Tanque T = new Tanque();
System.out.println("Quantos tanques foram testados?");
T.setValor(sc.nextInt());
for (int j=0;j<=T.getValor()-1;j++) {
System.out.println("A kilometragem por litro do "+(j+1)+"° Tanque é de "
+ T.kmLitro(T.tanques[0][j],T.tanques[1][j]));
}
System.out.printf("A Quilometragem total é de: %d \n", T.getKmTotal());
System.out.printf("A Quantidade de gasolina total é de %d \n",T.getGasolinaTotal());
sc.close();
}
}
I know I have to invoke the method/tank array but I don’t know/understand how yet...
"but error in array" - What error ? Which array ? On which line of code ? Invoke which method ?
– Isac