Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Looking for help and guidelines for a listprogram

843789Feb 18 2010 — edited Feb 21 2010
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 fully function, im feeling like im missing something but i dont know what.
Any help would be greatly appreciated
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 21 2010
Added on Feb 18 2010
16 comments
243 views