Hello, I'm trying to do the following program in JAVA. I find JAVA very confusing. Liked C++ much better. Anyway, here's what I'm trying to do:

Develop a program for a small auto dealership.
This program will keep track of the auto inventory using an object of the class
ArrayList. The dealer has a limit of 20 cars in inventory at one time due to
space restrictions. Your program must present the user (the dealer) with a menu
(e.g., press 1 for this and press 2 for that etc) allowing to:
• add new automobiles
• remove automobiles
• list automobiles
• search the inventory for cars of a particular model and year (e.g.,
list of 2009 Civics).

That's supposed to be my input area:

private static int getOptionFromUser(String... choices)
{
for (int i=0; i < choices.length; i++) System.out.println("" + (i + 1) + ". " + choices[i]);
Scanner s = new Scanner(System.in);
try
{
int opt = s.nextInt();
if (opt <=0 || opt > choices.length)
throw new IllegalArgumentException( "Invalid choice");
return opt;
}

catch(Exception ex)
{
System.out.println("Please enter a valid choice.");
return getOptionFromUser();
}
}

That's the main part..so far

int opt = getOptionFromUser("Add", "Remove", "Search", "List");
if (opt == 1) add_automobile();
else if (opt == 2) remove_automobile();
else if (opt == 3) search();
else list();

The search option is obviously still missing. The way it is not, is that ok? I have no idea how to implement the search though. I don't know how to do the search.
Help would be relly appreciated.

The search option is obviously still missing. The way it is not, is that ok? I have no idea how to implement the search though. I don't know how to do the search.
Help would be relly appreciated.

Create an 'Automobile' class. Your ArrayList should be filled with Automobiles. In the Automobile class, override the equals() method. The equals() method should be designed like so. After you do all of that, searching will be as simple as using the appropriate method listed here. (i.e. contains, indexOf(), whatever else you find).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.