THE CODE IS SUPPOSE TO PROMPT USER TO MAKE A SELECTION BY ENTERING X,Y,Z.
THEN IF X IS ENTERED- IT SEARCHES FOR NAME IN THE TEXTFILE phonebook.txt.
Y IS FOR EDITING THE NAMES AND Z FOR ADDING A DIFFERENT NAME
package phonebook ; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import java.io.*; public class phonebook { /** * @param args the command line arguments */ public static void main(String[] args) { boolean b; String holder; List<String> results = new ArrayList<String>(); int count = 0; String parameter; String paramet; String Z = null ; String X = null ; String Y = null ; try{ Scanner kbdin = new Scanner(System.in); System.out.println("Enter X to Search for name"); System.out.println("Enter Y to Edit name"); System.out.println("Enter Z to Add name"); paramet = in.readLine(); if (paramet!=X){ System.out.print(paramet); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter name:"); parameter = in.readLine(); System.out.println(""); File file = new File("C:\\Users\\musa\\Documents\\NetBeansProjects\\PhoneBook\\src\\phonebook\\phonenumber.txt"); Scanner s = new Scanner(file); while(b = s.hasNext()){ holder = s.next(); if(holder.startsWith(parameter, 0)) { results.add(holder); count++; } } System.out.println("+++++++ "+count+" OUTPUT +++++++"); if(results.isEmpty()){ System.out.println(); System.out.println("ZITA RASHAIKWA!!"); System.out.println(); } for(String r : results){ System.out.println(r); } System.out.println(""); } else if (paramet!=Y){ System.out.println("Enter name to edit"); Scanner kbdin = new Scanner(System.in); Scanner editname = new Scanner(System.in); String filename ="phonenumber.txt"; FileWriter targetFile = new FileWriter(filename); PrintWriter writer = new PrintWriter(targetFile); writer.println(editname); } else if (paramet!=Z){ System.out.println("Enter name to Add to contacts"); Scanner kbdin = new Scanner(System.in); Scanner addname = new Scanner(System.in); BufferedWriter out = new BufferedWriter(new FileWriter("phonebook.txt")); out.write("addname"); out.close(); } else { System.out.println("INVALID SELECTION!!"); } } catch(IOException e) {}} // TODO code application logic here }
The compile output is:
run:
Enter X to Search for name
Enter Y to Edit name
Enter Z to Add name
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code
at phonebook.phonebook.main(phonebook.java:39)
Java Result: