You are on page 1of 8

/* * To change this template, choose Tools | Templates * and open the template in the editor.

*/ //package mycontacts2; /** * * @author ja */ import java.io.*; import java.util.*; public class MyContacts2 { public public public public public public public public public public public public static static static static static static static static static static static static DataInputStream k = new DataInputStream(System.in); String IdNum[] = new String[100]; String FirstName[] = new String[100]; String LastName[]= new String[100]; String MiddleName[]= new String[100]; String Age[]= new String[100]; String Gender[]= new String[100]; String Status[]= new String[100]; String Address[]= new String[100]; String Occupation[]= new String[100]; String Email[]= new String[100]; MyContacts2 MCon=new MyContacts2();

public static int x=1; public static Scanner input=new Scanner(System.in); public static String id,fname,lname,mname,age,gender,status,address,occu pation,email; public static String Q,Q1; public static void main(String[] args)throws IOException { Menu(); } public static void Menu()throws IOException { int m; clrscr(); System.out.println("\t\t\t\t\tMENU\n"); System.out.println("\t\t\t[1] - Add Record"); System.out.println("\t\t\t[2] - Edit Record"); System.out.println("\t\t\t[3] - Delete Record"); System.out.println("\t\t\t[4] - Search Record"); System.out.println("\t\t\t[5] - View Record"); System.out.println("\t\t\t[6] - Exit Program\n"); System.out.print("\t\t\tSelect a menu: "); m=input.nextInt(); switch(m) { case 1: //ADD MyContacts2.addRecord();

break; case 2: //EDIT MyContacts2.editRec(); break; case 3: //DELETE MyContacts2.DeleteRecord(); break; case 4: //SEARCH MyContacts2.SearchRecord(); break; case 5: //VIEW MyContacts2.viewRecord(); break; case 6: //EXIT System.exit(0); break; default: break; } } public static void DeleteRecord()throws IOException { boolean bol = false; int indx=0; clrscr(); //String id; System.out.print("-->DELETE RECORDS<--\n\n\n"); System.out.print("Search Student ID: "); id=input.nextLine(); for(int i=1;i<IdNum.length;i++) { if(IdNum[i] !=null) { if(id.equalsIgnoreCase(IdNum[i])) { bol = true; indx = i; } } } if(bol==true) { System.out.print("Id Number: "+IdNum[indx].toUpperCase() + " " + " ()+ " "); System.out.print("Course: "+Gender[indx].toUpperCase()+ "); System.out.print("Name: "+FirstName[indx].toUpperCase()+ "); System.out.print("Course: "+LastName[indx].toUpperCase() "); System.out.print("Course: "+MiddleName[indx].toUpperCase "); System.out.print("Course: "+Age[indx].toUpperCase()+ "

" " " ()+ "

"); System.out.print("Course: "+Status[indx].toUpperCase()+ "); System.out.print("Course: "+Address[indx].toUpperCase()+ "); System.out.print("Course: "+Occupation[indx].toUpperCase "); System.out.print("Course: "+Email[indx].toUpperCase()+ " "); System.out.println(""); System.out.print("Are you sure to save this record?[y]-y

/[n]-no: "); Q =input.nextLine(); if(Q.equalsIgnoreCase("y")) { IdNum[indx] = null; FirstName[indx] = null; LastName[indx] = null; MiddleName[indx] = null; Age[indx] = null; Gender[indx] = null; Status[indx] = null; Address[indx] = null; Occupation[indx] = null; Email[indx] = null; for(int j=indx+1;j<IdNum.length;j++) { IdNum[j-1] = IdNum[j]; FirstName[j-1] = FirstName[j]; LastName[j-1] = LastName[j]; MiddleName[j-1]=MiddleName[j]; Age[j-1]=Age[j]; Gender[j-1]=Gender[j]; Status[j-1]=Status[j]; Address[j-1]=Address[j]; Occupation[j-1]=Occupation[j]; Email[j-1]=Email[j]; } System.out.println("Record succesfully deleted!" ); System.out.println("\n\n\n<Press Enter>"); Q1 = input.nextLine(); clrscr(); Menu(); }else { clrscr(); Menu(); } }else { System.out.print("ID Number not found!");

System.out.println("\n\n\n<Press Enter>"); Q = input.nextLine(); clrscr(); Menu(); } } public static void SearchRecord()throws IOException { boolean bol = false; int indx=0; clrscr(); System.out.print("-->SEARCH RECORDS<--\n\n\n"); System.out.print("Search ID Number: "); id = input.nextLine(); for(int i=1;i<IdNum.length;i++) { if(IdNum[i] !=null) { if(id.equalsIgnoreCase(IdNum[i])) { bol = true; indx = i; } } } if(bol==true) { System.out.print("Id Number: "+IdNum[indx].toUpperCase() + " ase()+ " e()+ " rCase()+ " "); System.out.print("Gender: "+Gender[indx].toUpperCase()+ " " + " Case()+ " "); System.out.println(""); System.out.println("\n\n\n<Press Enter>"); Q = input.nextLine(); clrscr(); Menu(); "); System.out.print("Status: "+Status[indx].toUpperCase()+ "); System.out.print("Address: "+Address[indx].toUpperCase() "); System.out.print("Occupation: "+Occupation[indx].toUpper "); System.out.print("Email: "+Email[indx].toUpperCase()+ " "); System.out.print("First Name: "+FirstName[indx].toUpperC "); System.out.print("Last Name: "+LastName[indx].toUpperCas "); System.out.print("Middle Name: "+MiddleName[indx].toUppe "); System.out.print("Age: "+Age[indx].toUpperCase()+ "

} else { System.out.print("ID Number not found!"); System.out.println("\n\n\n<Press Enter>"); Q = input.nextLine(); clrscr(); Menu(); } } public static void addRecord()throws IOException { clrscr(); System.out.print("-->ADD RECORDS<--\n\n\n"); System.out.print("ID Number:"); //id = input.nextLine(); id=k.readLine(); if (id.contentEquals(id) ) { System.out.println("ID Number already exist."); // addRecord(); } else { System.out.print("First Name: "); //fname = input.nextLine(); fname=k.readLine(); System.out.print("Last Name: "); lname = input.nextLine(); System.out.print("Middle Name: "); mname = input.nextLine(); System.out.print("Age : "); age = input.nextLine(); System.out.print("Gender: "); gender= input.nextLine(); System.out.print("Status: "); status = input.nextLine(); System.out.print("Address: "); address = input.nextLine(); System.out.print("Occupation: "); occupation = input.nextLine(); System.out.print("Email : "); email = input.nextLine(); System.out.print("Are you sure to save this record?[y]-y/[n]-no: " ); Q = input.nextLine(); } if(Q.equalsIgnoreCase("y")) { IdNum[x] = id; FirstName[x] = fname; LastName[x] = lname; MiddleName[x]=mname;

Age[x]=age; Gender[x]=gender; Status[x]=status; Address[x]=address; Occupation[x]=occupation; Email[x]=email; x++; clrscr(); Menu(); } else if(Q.equalsIgnoreCase("n")) { clrscr(); Menu(); } } public static void clrscr() { int i; for(i=0;i<=40;i++) { System.out.println(); } } public static void viewRecord()throws IOException { boolean ctr=false; clrscr(); System.out.print("-->VIEW RECORDS<--\n\n\n"); for(int i=1;i<IdNum.length;i++) { if(IdNum[i] !=null) { System.out.print("Id Number: "+IdNum[i].toUpperCase()+ " "); System.out.print("First Name: "+FirstName[i].toUpperC ase()+ " e()+ " se()+ " "); System.out.print("Gender: "+Gender[i].toUpperCase()+ " "); System.out.print("Status: "+Status[i].toUpperCase()+ " "); System.out.print("Address: "+Address[i].toUpperCase()+ " "); System.out.print("Occupation: "+Occupation[i].toUpperCas "); System.out.print("Last Name: "+LastName[i].toUpperCas "); System.out.print("Middle Name: "+MiddleName[i].toUpperCa "); System.out.print("Age: "+Age[i].toUpperCase()+ "

e()+ " ");

"); System.out.print("Email: "+Email[i].toUpperCase()+ "

System.out.println(""); ctr=true; } } if(ctr==false) { System.out.print("\nEMPTY DATABASE NO RECORDS FOUND!"); } System.out.println("\n\n\n<Press Enter>"); Q = input.nextLine(); clrscr(); Menu(); } public static void editRec()throws IOException { boolean bol = false; int indx=0; clrscr(); System.out.print("-->EDIT RECORDS<--\n\n\n"); System.out.print("Search ID Num: "); String sid = input.nextLine(); for(int i=1;i<IdNum.length;i++) { if(IdNum[i] !=null) { if(sid.equalsIgnoreCase(IdNum[i])) { bol = true; indx = i; } } } if(bol==true) { System.out.print("First Name: "); fname= input.nextLine(); System.out.print("Last Name: "); lname= input.nextLine(); System.out.print("Middle Name: "); mname= input.nextLine(); System.out.print("Age: "); age= input.nextLine(); System.out.print("Gender: "); gender= input.nextLine(); System.out.print("Status: "); status= input.nextLine();

System.out.print("Address: "); address=input.nextLine(); System.out.print("Occupation: "); occupation= input.nextLine(); System.out.print("Email: "); email= input.nextLine(); System.out.print("Are you sure to update this record?[y] -y/[n]-no: "); Q = input.nextLine(); if(Q.equalsIgnoreCase("y")) { FirstName[indx] = fname; LastName[indx] = lname; MiddleName[indx] = mname; Age[indx] = age; Gender[indx] = gender; Status[indx] = status; Address[indx]=gender; Occupation[indx] = occupation; Email[indx] = email; clrscr(); Menu(); } }else { System.out.print("ID Number not found!"); System.out.println("\n\n\n<Press Enter>"); Q = input.nextLine(); clrscr(); Menu(); } } }

You might also like