Arraylist
- From: "chris1980" <sulemanzia@xxxxxxxxx>
- Date: 28 Jan 2007 15:06:30 -0800
Hi. i am creating a program in which a user can add a car, view the
list of car, delete a car and search for a specific car. i can't go
any further because i am having problems in creating a method of
adding a car using Arraylist. i know i can't return the whole
arraylist but then what am i suppose to return? i might have questions
later on about deleting. here is my code.
[code]
import java.util.*;
import java.util.Arrays;
import java.util.Scanner;
class Car
{
public String addCar()
{
String make="";
String model="";
String year="";
ArrayList<String> cars = new ArrayList<String>();
Scanner s = new Scanner(System.in);
System.out.println("Enter make ");
cars.add(make);
System.out.println("Enter model ");
cars.add(model);
System.out.println("Enter the year ");
cars.add(year);
return cars;
}
}
class AddEntry
{
public static void main(String[] args)
{
Car car = new Car();
Scanner s = new Scanner(System.in);
String name;
String phone;
String address;
int choice;
System.out.println("*******************************************");
System.out.println("\t Wellcome to Mike DealerShip ");
System.out.println("*******************************************");
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();
if(choice==1)
{
car.addCar();
}
} while(choice!=4);
}
}
[/code]
error:
C:\Java programs\AddEntry.java:20: incompatible types
found : java.util.ArrayList<java.lang.String>
required: java.lang.String
return cars;
Thanks for the help. and yes for searching i am thinking of using
linear search but i read the api and i saw this iterator very useful
in arraylist. any comments ?
.
- Follow-Ups:
- Re: Arraylist
- From: Abhi
- Re: Arraylist
- From: John W. Kennedy
- Re: Arraylist
- Prev by Date: Re: How to detect blank input using Scanner?
- Next by Date: Re: Arraylist
- Previous by thread: How to detect blank input using Scanner?
- Next by thread: Re: Arraylist
- Index(es):
Relevant Pages
|