Thread: Java phonebook help
so i'm in process of making phonebook application , i'm looking guidance.
far application takes input .txt file , prints out first 3 lines.
asks user input information, , allows user search term inside entertered information.
want code read in .txt file, , ask user want search for, reply line information on, rest of information.
e.g. "enter search term" - 'ubuntu'
'ubuntu' found on line 22 , phone number 0123456789
suggestions?
(code below)
code: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 word search for: "); string word = fileoutput.readline(); string[] textsplit = text.split(" "); for(string str:textsplit) { if(str.equalsignorecase(word)) system.out.println(word + " can found here - " + text); else system.out.println("sorry can't find that, mind trying again?"); } } catch(ioexception e) { e.printstacktrace(); } } }
how considering classes this?
maybe have phone book class called phonebook, contained arraylist of contact classes.
create phonebook when start application passing name of txt file constructor:
myphonebook = new phonebook("mytxtfile.txt");
constructor read text file , create number of contact classes added arraylist. (try use arraylist rather using array).
phonebook class have method called lookup(string value) when called looked contact class in list had appropriate values.
paul
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Java phonebook help
Ubuntu
Comments
Post a Comment