Arraylist



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 ?

.



Relevant Pages

  • Re: About absolute reference frame......
    ... The centripetal force is real, ... door of a car pushing sideways on you as the car turns a corner. ... One person might say there is a force backwards on the voodoo head. ... The only agent available for such a force is the string. ...
    (sci.physics.relativity)
  • Re: hmmm ... a solution but not a high order procedure.
    ... Since ones that go together are likely to be adjacent in a sorted list, if you compare each pair of adjacent filenames with some sort of string difference function, and limit it to some magic number for "these two things are really different", then you can use my partition function to sort them for you. ... you stayed with car cdr and a couple of minor procedures ... ... (define (odd-numbers message liste) ...
    (comp.lang.scheme)
  • Re: hmmm ... a solution but not a high order procedure.
    ... you stayed with car cdr and a couple of minor procedures ... ... (define (position char string) ... Yes, you're right, higher order function for higher order ... (define (odd-numbers message liste) ...
    (comp.lang.scheme)
  • Re: non-lexicographic string comparison
    ... (define str-num-str car) ... (define str-num-num cdr) ... ((and (string? ...
    (comp.lang.scheme)
  • Re: Newbie - need a small push on recursion / higher order procedures
    ... seems that first referred to the first 'word' of the string sentence defined ... 'rest are the equivalent of first and rest (car and cdr) for lists??? ... (define (odd-numbers message liste) ...
    (comp.lang.scheme)