String match to the linkedlist element
Hi,
I have created a LinkedList and I don't know why I can't check to see if the String elements entered into the list(Toyota) matches the input from the user, here is a piece of my code:
public class Car
{ private LinkedList<Type> make = new LinkedList<Type>();
private String car;
public Car(String car)
{ this.car = car;
add();
check(); }
private void add()
{make.add(new Type("Toyota"));}
private void check()
{car = In.nextLine();
if(isCar(car))
car = In.nextLine();
else{ System.out.print("\t\tThat is not a valid");
System.out.print("\t\tEnter car: ");
car = In.nextLine();}}}
private boolean isCar(String car)
{ for (Type t: make)
if (t.matches(car))
return true;
return false; }
}
This is the Type class:
public class Type
{ private String type;
public Type(String type)
{ this.type = type;
}
public boolean matches(String car)
{ return this.type.equals(car); }
}