Results 1 to 4 of 4
- 09-06-2009, 05:24 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
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); }
}Last edited by jboy; 09-06-2009 at 05:30 AM.
- 09-06-2009, 05:50 AM #2
Why do you read in the car 2-3 times? Do you get "That is not a valid" message? What is "In"? Does it compile?
My Hobby Project: LegacyClone
- 09-06-2009, 06:25 AM #3
Member
- Join Date
- Aug 2009
- Posts
- 56
- Rep Power
- 0
Ok, thanks, I found out the I had an extra read in method which wasn't necessary. So I got it solved. Thanks anyway..
Last edited by jboy; 09-06-2009 at 06:53 AM.
- 09-06-2009, 07:02 AM #4
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Need help getting java drawing match to image.
By kiduut in forum New To JavaReplies: 9Last Post: 12-28-2008, 01:55 PM -
Convert Linked List Object element to String
By CirKuT in forum New To JavaReplies: 2Last Post: 12-13-2008, 05:22 AM -
Java Developer - Need Job - This is Perfect match
By ravisrivastava2003 in forum Java SoftwareReplies: 0Last Post: 12-10-2008, 07:35 PM -
How to limit selection to items that match a pattern in SWT Tree
By Java Tip in forum SWTReplies: 0Last Post: 07-07-2008, 04:51 PM -
Get all groups from a regular expression match?
By johann_p in forum New To JavaReplies: 0Last Post: 05-16-2008, 07:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks