liquidfunk
August 25th, 2010, 02:54 PM
So I'm in the process of making a phonebook application and I'm looking for some guidance.
So far this application takes the input .txt file and prints out the first 3 lines.
It then asks the user to input some information, and then allows the user to search for a term inside that entertered information.
What I want the code to do is to read in the .txt file, and ask the user what they want to search for, then reply with the line that the information is on, as well as the rest of the information.
E.g. "Enter the search term" - 'Ubuntu'
'Ubuntu' was found on line 22 and the phone number is 0123456789
Any suggestions?
(Code is below)
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class blondie
{
public static void main(String args[])
throws IOException
{
Scanner FileInput = new Scanner(new File("/Users/Josh/Dropbox/Jubilee Healthcare/Java app/Code/phone.txt"));
System.out.println("");
System.out.print("Name: ");
System.out.println(FileInput.nextLine());
System.out.print("Telephone Number: ");
System.out.println(FileInput.nextLine());
System.out.print("Address: ");
System.out.print(FileInput.nextLine());
System.out.println("");
System.out.println("");
BufferedReader FileOutput = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter information: ");
try
{
String text = FileOutput.readLine();
System.out.println("Enter the word to search for: ");
String word = FileOutput.readLine();
String[] TextSplit = text.split(" ");
for(String str:TextSplit)
{
if(str.equalsIgnoreCase(word))
System.out.println(word + " can be found here - " + text);
else
System.out.println("Sorry I can't find that, mind trying again?");
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
So far this application takes the input .txt file and prints out the first 3 lines.
It then asks the user to input some information, and then allows the user to search for a term inside that entertered information.
What I want the code to do is to read in the .txt file, and ask the user what they want to search for, then reply with the line that the information is on, as well as the rest of the information.
E.g. "Enter the search term" - 'Ubuntu'
'Ubuntu' was found on line 22 and the phone number is 0123456789
Any suggestions?
(Code is below)
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class blondie
{
public static void main(String args[])
throws IOException
{
Scanner FileInput = new Scanner(new File("/Users/Josh/Dropbox/Jubilee Healthcare/Java app/Code/phone.txt"));
System.out.println("");
System.out.print("Name: ");
System.out.println(FileInput.nextLine());
System.out.print("Telephone Number: ");
System.out.println(FileInput.nextLine());
System.out.print("Address: ");
System.out.print(FileInput.nextLine());
System.out.println("");
System.out.println("");
BufferedReader FileOutput = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter information: ");
try
{
String text = FileOutput.readLine();
System.out.println("Enter the word to search for: ");
String word = FileOutput.readLine();
String[] TextSplit = text.split(" ");
for(String str:TextSplit)
{
if(str.equalsIgnoreCase(word))
System.out.println(word + " can be found here - " + text);
else
System.out.println("Sorry I can't find that, mind trying again?");
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}