Re: Phone Directory program
Do you have any specific questions about your assignment?
Re: Phone Directory program
Yes
I used in this program Doubly Linked List
and this is the out put
http://www6.0zz0.com/2012/12/20/15/163771273.jpg
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
Re: Phone Directory program
Quote:
I want ues insert method
Is the insert() method defined yet? I don't see it in the code.
How is that method supposed to work? What args does it take and what does it return?
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'
Paste here.
Re: Phone Directory program
Yes My question is
This method
PHP Code:
public boolean insertAfter(double key, double dd)
{
Link current = first;
while(current.dData != key) // until match is found
{
current = current.next; // move to next link
if(current == null)
return false; // didn't find it
}
Link newLink = new Link(dd);
if(current==last)
{
newLink.next = null; // newLink --> null
last = newLink; // newLink <-- last
}
else
{
newLink.next = current.next; // newLink --> old next
current.next.previous = newLink; // newLink <-- old next
}
newLink.previous = current; // old current <-- newLink
current.next = newLink; // old current --> newLink
return true; // insert
}
How I can connect it with my program
Re: Phone Directory program
Quote:
How I can connect it with my program
You have to put the code into the program to be able to use it.
What class does it go in? Have you tried using the editor to copy and paste that code into the source for the class that you want it in?
Then compile it.
When there are no compiler errors, then code some uses of the method to see if it works correctly. Print out the list before the insert and after the insert to see if it worked correctly.
The code needs to be properly formatted. The indentations of the statements is wrong. Nested statements should be indented 3-4 spaces.
Re: Phone Directory program
I tries and I have add insertlist method BUT it have some errors .. could you plz hepl my to find what are the errors ....
those are the cods after adding the method // ??
main class
PHP Code:
//-------------------------------------------------------------------------------------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
PHP Code:
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
PHP Code:
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
PHP Code:
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
Re: Phone Directory program
Quote:
it have some errors
You forgot to post the text of the error messages.
If the errors are that the program does not do what you want, please post the output from the program and add comments to it explaining what is wrong and show what the output should be.
Re: Phone Directory program
Re: Phone Directory program
Please copy the full text of the compiler's error messages and paste them here. Images are hard to work with. I can not copy and paste text from the error message to explain it. With posted text I can.
Here is a sample of a compiler's error message:
Code :
TestSorts.java:138: cannot find symbol
symbol : variable var
location: class TestSorts
var = 2;
^
It shows the source line and line number and describes the error. I can't see the source line and line number from the image you posted.
The above error message was from using the javac command.
With an IDE you need to find someone that can come to your PC, look at its screen and help you solve the errors.
Re: Phone Directory program
Re: Phone Directory program
Sorry, I can not copy text from images to be able to suggest fixes for the errors.
You need to copy and paste the text of the error messages here.
One problem I can see is the compiler cannot find a definition for the last variable. Where is it defined?
Is its definition in scope (within the same pair of {}s) where it is referenced?
That is the same problem for all the cannot find errors.