help with this program...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • babynailah
    New Member
    • Sep 2006
    • 7

    #1

    help with this program...

    This is what i have to do and this is all i have....
    HELP ME PLEASE MY GRADE IN CLASS DEPENDS ON IT!!!!


    Your problem is to simulate certain aspects of a cell phone. The following features are required for the first assignment.


    The interface must be a GUI that resembles a cell phone.
    The cell phone must contain an array to hold a list of contacts. Each contact has a name and number. Make the size of the array 5 and be sure to account for increasing the array size if more than 5 numbers are added.
    You should be able to add a contact to the list.
    The Cell phone should have a selection that allows you to view your telephone number.
    Modify the phone contacts to be stored in a link list.
    The contacts must be stored in alphabetical order
    You must have an option to edit a contact.
    You must have an option to delete a contact.
    Implement the Outgoing Calls feature.
    When a call is made, it is added to the outgoing calls list.
    The outgoing calls list must be implemented as a list stack.
    You should be able to view the outgoing calls.

    THIS IS WHAT I CURRENTLY HAVE....

    import javax.swing.*;
    import javax.swing.bor der.*;
    import java.awt.*;
    import java.awt.event. *;
    import java.applet.*;


    public class CellPhone2 extends Applet implements ActionListener
    {

    TextArea textarea;


    JLabel phoneNumberLabe l,dialLabel,Vie wNumberLabel,St oreNumberLabel, phoneLabel;
    Font italic =new Font("Helvetica ", Font.ITALIC,15) ;


    JButton numNine,numEigh t,numSeven,numS ix,numFive,numF our,numThree,nu mTwo,numOne,num Zero,numStar,nu mPound,

    public void init()
    {


    Container container = new Container();
    container.setLa yout( new FlowLayout() );


    container.setBa ckground(Color. black);
    container.setLa yout(new GridLayout(4,4, 4,4));



    int rows = 10;
    int cols = 30;
    textarea = new TextArea("", rows, cols);


    phoneLabel = new JLabel( "Sprint" );
    phoneLabel.setF ont(italic);
    container.add( phoneLabel);

    ViewNumberButto n = new JButton( "Contacts" );
    ViewNumberButto n.addActionList ener( this );
    container.add(V iewNumberButton );

    clearButton = new JButton( "Clear" );
    clearButton.add ActionListener( this );
    container.add(c learButton);

    dialButton = new JButton( "Dial" );
    dialButton.addA ctionListener( this );
    container.add(d ialButton);

    StoreNumberButt on = new JButton( "Store" );
    StoreNumberButt on.addActionLis tener( this );
    container.add(S toreNumberButto n);

    SearchButton = new JButton( "Search" );
    SearchButton.ad dActionListener ( this );
    container.add(S earchButton);

    numNine = new JButton( "9" );
    numNine.addActi onListener( this );
    container.add(n umNine);


    numEight = new JButton( "8" );
    numEight.addAct ionListener( this );
    container.add(n umEight);


    numSeven = new JButton( "7" );
    numSeven.addAct ionListener( this );
    container.add(n umSeven);


    numSix = new JButton( "6" );
    numSix.addActio nListener( this );
    container.add(n umSix);


    numFive = new JButton( "5" );
    numFive.addActi onListener( this );
    container.add(n umFive);


    numFour = new JButton( "4" );
    numFour.addActi onListener( this );
    container.add(n umFour);


    numThree= new JButton( "3" );
    numThree.addAct ionListener( this );
    container.add(n umThree);


    numTwo = new JButton( "2" );
    numTwo.addActio nListener( this );
    container.add(n umTwo);


    numOne = new JButton( "1" );
    numOne.addActio nListener( this );
    container.add(n umOne);

    numStar = new JButton( "*" );
    numStar.addActi onListener( this );
    container.add(n umStar);

    numZero = new JButton( "0" );
    numZero.addActi onListener( this );
    container.add(n umZero);

    numPound = new JButton( "#" );
    numPound.addAct ionListener( this );
    container.add(n umPound);



    Panel displayPanel= new Panel();
    displayPanel.se tLayout (new BorderLayout ());
    displayPanel.ad d("Center",phon eLabel);
    add(textarea,Bo rderLayout.SOUT H);
    add("Center",ph oneLabel);



    Panel buttonPanel = new Panel();
    buttonPanel.set Layout(new GridLayout(1, 1, 4, 4));
    buttonPanel.add ("West",ViewNum berButton);
    buttonPanel.add ("Center",dialB utton);
    buttonPanel.add ("East",StoreNu mberButton);
    buttonPanel.add ("North",clearB utton);
    add("West", buttonPanel);

    Panel numberPanel= new Panel();
    numberPanel.set Layout(new GridLayout(1, 1, 6, 6));
    numberPanel.add ("West", numOne);
    numberPanel.add ("Center", numTwo);
    numberPanel.add ("East", numThree);
    add("South",num berPanel);

    Panel number2Panel= new Panel();
    number2Panel.se tLayout(new GridLayout(1, 1, 6, 4));
    number2Panel.ad d("West", numFour);
    number2Panel.ad d("Center", numFive);
    number2Panel.ad d("East", numSix);
    add("East",numb er2Panel);

    Panel number3Panel=ne w Panel();
    number3Panel.se tLayout(new GridLayout(1, 1, 4, 4));
    number3Panel.ad d("West", numSeven);
    number3Panel.ad d("Center", numEight);
    number3Panel.ad d("East", numNine);
    add("South",num ber3Panel);

    Panel number4Panel= new Panel();
    number4Panel.se tLayout(new GridLayout(1, 1, 4,0));
    number4Panel.ad d("West", numStar);
    number4Panel.ad d("Center", numZero);
    number4Panel.ad d("East", numPound);
    add("South",num ber4Panel);


    Panel number5Panel= new Panel();
    number5Panel.se tLayout(new GridLayout(1, 1, 4,0));
    number5Panel.ad d("Center", SearchButton);
    add("South",num ber4Panel);



    }




    public void add()
    {
    DoubleLink dl = new DoubleLink();
    textarea.setTex t("Enter Full Name: ");
    String name = data.next();
    textarea.setTex t("Enter Phone Number: ");
    String phoneNum = data.next();
    textarea.setTex t("Data Entered!");
    Contact ph = new Contact(name, number);
    dl.add(ph);
    }




    public void delete()
    {
    DoubleLink dl = new DoubleLink();
    textarea.setTex t("Enter Full Name To Delete Contact: ");
    String name = data.next();
    boolean delete = dl.isEmpty(name );
    if(delete == false)
    textarea.setTex t("Contact does not exist");
    else
    dl.isEmpty(name );
    }


    public void search()
    {
    textarea.setTex t("Enter Full Name To Search Contact: ");
    String name = data.next();
    Contact search = dl.retrieve(nam e);
    if (search == null)
    textarea.setTex t("Wasnt found");
    else
    return;

    }


    public void view()
    {
    DoubleLink dl = new DoubleLink();
    textarea.setTex t("[Phone Book List]");
    dl.traverse();
    }



    public void actionPerformed (ActionEvent thisEvent)
    {

    Object source = thisEvent.getSo urce();
    if(source == ViewNumberButto n)
    view();
    if(source==clea rButton)
    delete();
    if(source==Stor eNumberButton)
    add();
    if(source==Sear chButton)
    search();


    }
    ;


    }

    }END OF CELL PHONE CLASS

    public class DoubleLink1 implements CellPhoneShell
    {
    private NodeData head;
    private NodeData tail;
    public DoubleLink1()
    {
    this.tail = null;
    this.head = null;
    }
    public void add(Contact data)
    {
    NodeData newNode = new NodeData(data);
    if(head != null)
    {
    newNode.next = head;
    head.prev = newNode;
    head = newNode;
    }
    else
    {
    head = tail = newNode;
    }
    }

    public Contact retrieve(String name)
    {
    NodeData current = head;
    while(current !=null)
    {
    if(current.data .getName().equa ls(name))
    return current.data;
    current = current.next;
    }
    return null;
    }

    public void traverse()
    {
    NodeData current = head;
    while(current !=null)
    {
    (current.getDat a());
    current = current.next;
    }

    }

    public boolean isEmpty(String name)
    {
    NodeData current = head;
    NodeData previous = head.prev;
    NodeData next = head.next;
    boolean found = false;
    if (head == null)
    return false;
    while(current != null)
    {
    if(current.data .getName().equa ls(name))
    {
    found = true;
    return found;
    }
    previous = current;
    current = current.next;
    if (current != null)
    next = current.next; }
    if (found)
    {
    if (previous == null)
    head = head.next;
    else if (next == null)
    tail = tail.prev;
    else {
    previous = current.next;
    next = current.prev;
    }
    }

    return found;

    }

    }END OF DOUBLE LINK CLASS

    public class NodeData
    {
    Contact data;
    NodeData next;
    NodeData prev;
    public NodeData(Contac t newPhone)
    {
    data = newPhone;
    next = prev = null;
    }
    public Contact getData()
    {
    return data;
    }
    public void setData(String name, String number)
    {
    data = new Contact(name, number);
    }
    }END OF NODE DATA
    class Contact {
    public Contact(String name, String number) {
    this.name = name;
    this.number = number;
    }

    public String getName()
    {
    return name;
    }


    public String toString() {
    return name + " : " + number;
    }

    String name;
    String number;

    }END OF CONTACT CLASS

    public interface CellPhoneShell
    {
    public void add(Contact newPhone);
    public boolean isEmpty(String name);
    public void traverse();
    public Contact retrieve(String name);
    }END OF INTERFACE

    WHAT AM I DOING WRONG???
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    I failed to compile your code, please have a look at the traverse method and repost it again using code tags.

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      My friend, your code looks very bad. You need to look at a swing tutorial.
      Try to stick to swing only not to mix awt and swing.
      If you need the code urgently, then I suggest we work on the one I posted earlier and adapt it to suit your requirements. You understand of course that we'd have to work through it together.

      Comment

      Working...