I've been learning java for a little over a month with no previous OOP experience, so please provide simple answers!
The project I'm working on is essentially a simple game. I take a txt file with a variable number of vehicle names, and allow a user to enter a vehicle name followed by a command.
How do I create an object for each item in an arraylist?
This is what I have so far (I put an example of what I'm trying to do in code comments):
public class VehicleApp {
public static void main(String[] args) throws FileNotFoundException, IOException{
File myDir = new File(System.getProperty("user.dir"));
File myFile = new File(myDir, "vehicleNames.txt");
FileReader in = new FileReader(myFile);
BufferedReader br = new BufferedReader(in);
ArrayList<String> vehicleList = new ArrayList<>();
int i = 0;
String line = null;
while((line = br.readLine()) != null){
vehicleList.add(line);
System.out.println(vehicleList.get(i));
//What I'm essentially trying to accomplish:
//Vehicle vehicleList.get(i) = new Vehicle();
i++;
}
br.close();
System.out.println("Enter user input as such:\n" +
"<vehicle name>, <command>");
}
}