So i have a String array
private String[] transmission = {"Drive", "Park", "Reverse"};
Here is my set method, I'm practicing my switch statement as I don't use it often.
public void setTransmission(String[] transmission) {
System.out.println("To change the transmission, enter D for Drive,P for Park or R for reverse");
switch (input.nextLine()) {
case "D":
case "d":
System.out.println("The Car is currently in Drive.");
transmission[0] = this.transmission[0];
break;
case "P":
case "p":
System.out.println("The Car is currently in Park.");
transmission[1] = this.transmission[1];
break;
case "R":
case "r":
System.out.println("The Car is currently in Reverse");
transmission[2] = this.transmission[2];
break;
}
Here is the real PROBLEM. In my getMethod it only prints the first index in the array:
public String getTransmission()
{
return String.format("The car is currently in %s",transmission);
}
How can i get it to print what the user entered? I know i could just use a string variable but i would prefer to use an array.
setTransmission
method. I.ethis.transmission[0] = transmission[0];
and so on. – Alexis C. Feb 17 '14 at 20:11transmission[index]
at the getter. – Smutje Feb 17 '14 at 20:14getTransmission
method. Should it return the content of the all array or not? – Alexis C. Feb 17 '14 at 20:16String
value itself, or as anint
indicating an index into the array. Assign this field within thesetTransmission
method. – David Wallace Feb 17 '14 at 20:16