Vergleich der Benutzer-Eingabe-string zu string Lesen aus Textdatei

Schreibe ich momentan das Programm, dass ich benötigt, um Lesen Informationen aus text-Datei, und vergleichen Sie dann die info Lesen, um eine Benutzer-Eingabe und-Ausgabe eine Meldung, wenn es ein Spiel ist oder nicht.

Derzeit haben diese. Das Programm ist erfolgreich Lesen der Daten angegeben, aber ich kann nicht scheinen, um zu vergleichen, die Saiten richtig am Ende, und drucken Sie ein Ergebnis.

Code unten jede mögliche Hilfe würde sehr geschätzt werden.

import java.util.Scanner;      //Required for the scanner
import java.io.File;               //Needed for File and IOException 
import java.io.FileNotFoundException; //Required for exception throw

//add more imports as needed

/**
 * A starter to the country data problem.
 * 
 * @author phi 
 * @version starter
 */
public class Capitals
{
    public static void main(String[] args) throws FileNotFoundException //Throws Clause Added
    {
        //ask the user for the search string
        Scanner keyboard = new Scanner(System.in);
        System.out.print("Please enter part of the country name: ");
        String searchString = keyboard.next().toLowerCase();

        //open the data file
        File file = new File("CountryData.csv");

        //create a scanner from the file
        Scanner inputFile = new Scanner (file);

        //set up the scanner to use "," as the delimiter
        inputFile.useDelimiter("[\\r,]");

        //While there is another line to read.
        while(inputFile.hasNext())
        {
            //read the 3 parts of the line
            String country = inputFile.next(); //Read country
            String capital = inputFile.next(); //Read capital
            String population = inputFile.next(); //Read Population

            //Check if user input is a match and if true print out info.
            if(searchString.equals(country))
            {
                System.out.println("Yay!");
            }
            else
            {
                System.out.println("Fail!");
            }
        }

        //be polite and close the file
        inputFile.close();
    }
}
InformationsquelleAutor user2285167 | 2013-04-16
Schreibe einen Kommentar