Hello everyone, im writing this post because im in need of some help or guidelines. My programs function is to be able to store cars, with this i mean being able to: add, delete and view the list of cars added.
Everything is supposed to be stored in a txt file.
This is the code i have so far, unfortunately i havent been able to get it to work.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Car {
String make;
String model;
String year;
public Car(Scanner s) {
System.out.println("Enter make ");
make = s.nextLine();
System.out.println("Enter model ");
model = s.nextLine();
System.out.println("Enter the year ");
year = s.nextLine();
}
}
class CarList {
private List<Car> list = new ArrayList<Car>();
public void addCar(Scanner s) {
list.add(new Car(s));
}
}
class AddEntry {
public static void main(String[] args) {
CarList carlist = new CarList();
Scanner s = new Scanner(System.in);
int choice;
System.out.println("\t Welcome to the car ");
do {
System.out.println("Make a selection ");
System.out.println("1. Add a Car ");
System.out.println("2. View car list ");
System.out.println("3. Delete a car ");
System.out.println("4. Quit ");
System.out.print("Enter your choice plz: ");
choice = s.nextInt();
s.nextLine(); // Discard the rest of the line
if (choice == 1) {
carlist.addCar(s);
}
} while (choice != 4);
}
}
Regards