I need to make a method that randomly chooses one of the strings in my "carmake" array. I am stuck in my setCarMake method. The same applies for the color of the car(that method will be made after i finish this one). Here is my current code.
public class Cars {
public String[] carmake = {"Audi", "BMW" , "Mercedes-Benz", "Lexus", "Volkswagen"};
public String[] carcolor = {"Black", "Yellow", "Red", "Grey"};
//
public int caryear;
public int speed;
public void setCarMake(){
Random rand = new Random(14335);
carmake.rand.nextInt(carmake.length);
}
public int GetYear(){
int max = 2015;
int min = 1999;
Random rand = new Random();
caryear = rand.nextInt((max-min)+1) + min ;
return caryear;
}
public void execute(){
System.out.println(caryear + " " + carmake);
}
}
Please help!
setCarMake()does not return a value. You need to set the return type toStringand add areturnstatement.