Hi
I have project in Data Structures
this is the question
1.Phone Directory
Design a phone directory that will be able to store names of teachers and their office phone numbers. Your system should be able to "quickly" insert or search the entries.
I want ues insert method
so the user can add teacher name, Id,Phone number and teacher room in to current list
how can I do this
I tries and I have add insertlist method BUT it have some errors .. could you please hepl my to find what are the errors ....
those are the cods after adding the method // ??
and this is 4 class for the program I have used Doubley linked list
main class
users class
Link class
linkList class
I have project in Data Structures
this is the question
1.Phone Directory
Design a phone directory that will be able to store names of teachers and their office phone numbers. Your system should be able to "quickly" insert or search the entries.
I want ues insert method
so the user can add teacher name, Id,Phone number and teacher room in to current list
how can I do this
I tries and I have add insertlist method BUT it have some errors .. could you please hepl my to find what are the errors ....
those are the cods after adding the method // ??
and this is 4 class for the program I have used Doubley linked list
main class
//-------------------------------------------------------------------------------------Backages import java.util.*; import java.util.Scanner; import java.awt.*; import java.awt.event.*; import javax.swing.*; //--------------------------------------------------------------------------------------Class Main public class Main extends JFrame { final Users theUser = new Users(); //------------------------------------------------------------------------------------1--Method main public static void main(String[] args) { new Main().setVisible(true);//call method Main }//end public static void main //-----------------------------------------------------------------------------------2--Mathod Main public Main() { theUser.Users(); //------------------ setTitle("Phone Directory"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //---------------------------------------------------------------------------Date-Photo-size-color Date da = new Date(); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); contentPane.setBackground(Color.green); setSize(300,300); //------------------- JLabel time = new JLabel(" Today is : " +da); getContentPane().add(time); //---------------- setResizable(false); setLocationRelativeTo(null); String imgStr1 = "c://EQLS.png"; ImageIcon image = new ImageIcon(imgStr1); JLabel label1 = new JLabel(" ", image, JLabel.CENTER); getContentPane().add(label1); validate(); setVisible(true); //-----------------------------------------------------------------------------------------Button1 JButton button1 = new JButton("*~...~* Welcome *~...~*"); button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((Component) e.getSource(), "\n\nThe main idea behind my system is\n\n\n to make the search for teacher information easier using a computer system.\n\n"); } });//end button1 //-----------------------------------------------------------------------------------------Button2 JButton button2 = new JButton("Main User Access: Phone Directory"); button2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String Option1 = JOptionPane.showInputDialog(null,"Please Enter The Number of Choice !? \n1) View list ROOM\n2) SEARCH THE DATA OFTEACHER\n3) Remove DATA OF TEACHER list\n4) Delete\n5) Return\n6) Exit\n", "Phone Directory Options", JOptionPane.INFORMATION_MESSAGE); int ConvOption1 = Integer.parseInt(Option1); theUser.mainUser(ConvOption1,Option1);//go to main User method }//end method public void actionListener String Option1 = JOptionPane.showInputDialog( });//end button2 //-----------------------------------------------------------------------------------------Button3 JButton button3= new JButton("Exit"); button3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { int result = JOptionPane.showConfirmDialog((Component) e.getSource(),"Close Phone Directory SYSTEM"); if (result == JOptionPane.YES_OPTION) {System.exit(0);} } });//end button3 //------------------------------------------------------------------------------------------ // setLayout(new FlowLayout(FlowLayout.CENTER)); setLayout(new GridLayout(8,4)); getContentPane().add(button1); getContentPane().add(button2); getContentPane().add(button3); }//end public method Main //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// }//end class Main
users class
import javax.swing.JFrame; import java.util.Scanner; import javax.swing.JOptionPane; class Users { linkList theList = new linkList(); Scanner input = new Scanner(System.in); int a = 0; int b = 0; int key,r; Link v,d, f; public void Users() { JOptionPane.showMessageDialog (null, " *~...~* WELCOME *~...~*\n\n PHONE DIRECTORY SYSTEM\n\n For Login Please Click Ok\n\n", " {ELECTRONIC SYSTEM OF PHONE DIRECTORY]", JOptionPane.INFORMATION_MESSAGE); JFrame frame = new JFrame(); int SENTINEL = 123; //password number String str; //password number which the user will Enter it int password = 0; int counter = 5; while (counter != 0 && password != SENTINEL) { str = JOptionPane.showInputDialog("Enter Password"); password = Integer.parseInt(str); if(password == SENTINEL) { JOptionPane.showMessageDialog(null, "CORRECT"); System.out.println("\n\t*~...~* The Messages of PHONE DIRECTORY SYSTEM *~...~*\n\n-------------------------------------------------------------------------- \n"); } else if(password!=SENTINEL) { JOptionPane.showMessageDialog(null, "Wrong try again"); } counter = counter-1; if (counter == 0) { JOptionPane.showMessageDialog(null, "Acces Denied!!! \nPlease contact Helpdesk"); System.exit(0); } } String backupDir="" ; theList.insertFirst(16, "08120014", "Ms. Fahmeeda Aziz","043258088"); theList.insertFirst(15, "08120014", "Dr. Farhana Shaheen ","043258088"); theList.insertFirst(14, "08120014", "Dr. Fatima Al-Zwaihri ", "043258088"); theList.insertFirst(13, "08120014", "Dr. Tahani Sindi ", "043258088"); theList.insertFirst(12, "08120014", "Dr. Nagla Osman ", "043935024"); theList.insertFirst(11, "08120014", "Ms. Atiya Azmi ", "043258088"); theList.insertFirst(10, "08120014", "Ms. Aisha Al-Johani ", "043258088"); theList.insertFirst(9, "08120014", "Ms. Siti Haryani Mohd ", "043935024"); theList.insertFirst(8,"08120014", "Ms.Humera Ghani ", "043258088"); theList.insertFirst(7, "08120014", "Ms. Salma Sadiqha ", "043258088"); theList.insertFirst(6, "08120014", "Ms. Azra Sultana ", "043935024"); theList.insertFirst(5, "08120014", "Ms. Ruchi Tuli ", "043258088"); theList.insertFirst(4, "08120014", "Ms. Fozia Noor ", "043258088"); theList.insertFirst(3, "08120014", "Ms. Kajal nusratullah ", "043258088"); theList.insertFirst(2, "08120014", "Ms.Anusuyah Subbarao ", "043935024"); theList.insertFirst(1, "08120014", "Ms. Aizal Yusrina ", "043258088"); } public void mainUser(int ConvOption1,String Option1) { while(ConvOption1!=6) { switch (ConvOption1) // 5 cases { case 1: { theList.displayList(); System.out.println("---------------------------------------------------------------------------\n"); } break; case 2: { // Option1 = JOptionPane.showInputDialog("Enter how MANY TEACHERS U WANT TO FIND"); // a = Integer.parseInt(Option1); System.out.println("Enter how MANY TEACHERS U WANT TO FIND"); a=input.nextInt(); //theList. display1() ; for(int j=1;j<=a;j++) { // Option1 = JOptionPane.showInputDialog("\nEnter Number of Teacher Room ÏÏ "+j+" ÏÏ "); // b = Integer.parseInt(Option1); System.out.println("\nEnter Number of Teacher Room ÏÏ "+j+" ÏÏ "); b=input.nextInt(); f = theList.find( B)/>/>; // find item if( f != null) { System.out.println("\nTEACHER NAME IS: "+f.Teacher_Name+"\nTEACHER ID: "+f.teacher_ID+"\nPHONE NUMBER IS: "+f.Phone_number); // JOptionPane.showMessageDialog(null,"\nTEACHER NAME IS: "+f.Items+"\nTEACHER ID: "+f.qui+"\nPHONE NUMBER IS: "+f.price); // System.out.println("\nQuintity of "+f.Items+" Now is "+e); } else { System.out.println("we did FOUND "+f.Teacher_Name); } } // System.out.println("\n ÒÒ price ="+t); System.out.println("---------------------------------------------------------------------------\n"); } break; case 3: { System.out.println("Enter THE ROOM NUMBER OF TEACHER "); int key=input.nextInt(); Link i = theList.delete(key); // delete item if( i != null ) { System.out.println("Deleted NUMBER OF ROOM : "+ i.Room_Number+"\n"); System.out.println("Delet the ID : "+i.teacher_ID +"\n"); System.out.println("Delet the Name Of TEACHER : "+ i.Teacher_Name+"\n" ); System.out.println("Delet the PHONE NUMBER : "+i.Phone_number+"\n"); System.out.println("SUCCESSFUL DELET"); } else { System.out.println("Can't delete "); System.out.println("the data still in list "+i); } System.out.print("---------------------------------------------------------------------------\n"); } break; case 4: { theList.display2(); System.out.println("Enter ROOM NUMBER:>"); key= input.nextInt(); Link i = theList.delete(key); System.out.print("---------------------------------------------------------------------------"); System.out.println("\nlist after EDIT:>"); theList.display2(); System.out.println("---------------------------------------------------------------------------\n"); } break; case 5: { theList.display2(); System.out.println("Enter New Teacher Room NUMBER:>"); key= input.nextInt(); Link i = theList.insertLast(key); System.out.print("---------------------------------------------------------------------------"); System.out.println("\nlist after EDIT:>"); theList.display2(); System.out.println("---------------------------------------------------------------------------\n"); } break; }//end switch if(ConvOption1>6) { JOptionPane.showMessageDialog(null, "YOUAR INPUT NUMBER NOT IN THE LIST\n PLEASE, TRY AGAIN"); } Option1 = JOptionPane.showInputDialog("\n1-Show List of TEACHERS\n2-SEARCH \n3-Remove \n4-Borrow\n5-Return\n6-Exit"); ConvOption1 = Integer.parseInt(Option1); }//end while } }//end mainUser method
Link class
class Link { public int Room_Number; public String teacher_ID; public String Teacher_Name; public String Phone_number; // data item public Link next; // next link in list // ------------------------------------------------------------- public Link(int a, String b, String teacher, String Phone) // constructor { Room_Number = a; teacher_ID = b; // constructor Teacher_Name = teacher; Phone_number = Phone; } // set to null) // ------------------------------------------------------------- public void displayLink1() // display ourself { System.out.println("\t" + Teacher_Name + "\t\t{" + Room_Number + "}"); System.out.println(""); } public void displayLink2() // display ourself { System.out.print("\t" + Room_Number); System.out.print("\t" + teacher_ID); System.out.print("\t" + Teacher_Name); System.out.println("\t\t{" + Phone_number + "}"); } }
linkList class
class linkList { private Link first; // ref to first link on list // ------------------------------------------------------------- public linkList() // constructor { first = null; // no links on list yet } // ------------------------------------------------------------- public boolean isEmpty() // true if list is empty { return (first == null); } // ------------------------------------------------------------- // insert at start of list public String insertFirst(int a, String SD, String teacher, String Phone) { // make // new // link Link newLink = new Link(a, SD, teacher, Phone); newLink.next = first; // newLink --> old first first = newLink; // first --> newLink return first.Room_Number + " " + first.teacher_ID + " " + first.Teacher_Name + "{" + first.Phone_number + "}"; } // ------------------------------------------------------------- public Link find(int key) // find link with given key { // (assumes non-empty list) Link current = first; // start at 'first' while (current.Room_Number != key) // while no match, { if (current.next == null) // if end of list, return null; // didn't find it else // not end of list, current = current.next; // go to next link } return current; // found it } // ///////////////////////////////////// public Link delete(int key) // delete link with given key { // (assumes non-empty list) Link current = first; // search for link Link previous = first; while (current.Room_Number != key) { if (current.next == null) return null; // didn't find it else { previous = current; // go to next link current = current.next; } } // found it if (current == first) // if first link, first = first.next; // change first else // otherwise, previous.next = current.next; // bypass it return current; } // ------------------------------------------------------------- public void insertLast( int key) { Link newLink = new Link(key); // make new link if( isEmpty() ) // if empty list, first = newLink; // first --> newLink else { last.next = newLink; // old last --> newLink newLink.previous = last; // old last <-- newLink } last = newLink; // newLink <-- last } // ------------------------------------------------------------- public void displayList() { System.out.println("\t\t\n\n *~...~* Welcome *~...~*\n\n "); System.out.print("\n\n\t\t The Menue \n\n"); System.out.println("\n\t :: NAME OF TEACHERS ::\t\t:: NUMBER OF ROOM ::"); System.out.println(""); Link current = first; // start at beginning of list while (current != null) // until end of list, { current.displayLink1(); // print data current = current.next; // move to next link } System.out.println(""); } public void display2() { System.out.print("\t\t *~...~* The Menue *~...~* \n\n"); System.out.println("\n\tR.N. ID TEACHER NAME \t PHONE NUMBER\n "); Link current = first; // start at beginning of list while (current != null) // until end of list, { current.displayLink2(); // print data current = current.next; // move to next link } System.out.println(""); } // ------------------------------------------------------------- } // end class LinkList