vendredi 27 mai 2016

(Java) getting values from LinkedList according to user input

Facing some issues with my lab assignment :/ I've done trouble shooting to find that both there's nothing wrong with my filereader/bufferedreaders, Vehicle method and LinkedList values

I'm found out that I'm having Problems getting the if statement to work I do not know How do I compare the current linkedlist data extracted from my file.txt using tokenizer to pass into given fields with userinput using if/else??

public class Lab6 {  

//I've done troubleshooting for my programme, 
    //the only problem that remains is my if/else statement which 
    //I have no idea how to go about doing

    //I'm having Problems getting the if statement to work 
    //How do I compare linkedlist data with userinput using if/else??
final String INPUT_PROMPT = "\nPlease enter the search word " + "that you would like to obtain more information on:";
String tokenizer;
FileReader fr = new FileReader("Vehicle.txt");
BufferedReader br = new BufferedReader(fr);
LinkedList<Vehicle> list = new LinkedList<Vehicle>();
String line;


while (line !=null)
{
  line = br.readline;

     tokenizer = new StringTokenizer(line, ",");
 group = tokenizer.nextToken();
 brand = tokenizer.nextToken();
 model = tokenizer.nextToken();
 rate = Double.parseDouble(tokenizer.nextToken());
Vehicle newVehicle = new Vehicle(group, brand, model, rate);
list.add(newVehicle);

}
System.out.println(INPUT_PROMPT);
try{
BufferedReader ubr = new BufferedReader(new InputStreamReader (System.in));
String uline = ubr.readLine();

for(int i = 0; i< list.size(); i++)
    {
//I'm stuck at the if //it's the only part that doesn't work for my codes
if(list.get(i)== uline.contains(temp))
        {
            //print out the information of the vehicle that match user input
            System.out.println(list.get(i));

        }   
    }
//etc
catch(IOException e)
        {
            System.out.println(e);
        }

        catch (Exception e) 
        {
            System.out.println("Input error!" + e);
        }

}

Aucun commentaire:

Enregistrer un commentaire