Results 1 to 5 of 5
  1. #1
    Veton is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default I have troubles with this code ..!

    I started to work with eclipse last week.. And i don have any idea what to do with this code,.. In data Structures And Algorithms.. :( Help Me.. !


    this is the code


    public class MyQueue {
    int n = 5;
    int[] a = new int[n];
    int h = 0;
    int t = 0;
    public boolean isEmpty()
    {


    }
    public int first()
    {


    }
    public int size()
    {


    }
    public void pushBack(int e)
    {


    }
    public void popFront()
    {

    }
    public void print()
    {
    System.out.println("------------------------------------------------------------------");
    System.out.println("| h \t| t \t| a[0]\t| a[1]\t| a[2]\t| a[3]\t| a[4]\t| size() |");
    System.out.println("-------------------------------------------------------------------");
    System.out.print("| " + h + "\t| " + t +"\t|");
    for(int i=0; i<a.length; i++){
    System.out.print(" "+a[i]+ "\t");
    }

    System.out.println("| "+size()+ "\t|");
    System.out.println("-------------------------------------------------------------------\n");
    }

    public static void main(String[] args)
    {

    MyQueue q = new MyQueue();
    q.pushBack(5);
    q.print();
    //-----------------
    q.pushBack(2);
    q.print();
    q.pushBack(1);
    q.print();
    q.pushBack(7);
    q.print();
    q.pushBack(6);
    q.print();
    //----------------
    q.popFront();
    q.print();
    q.popFront();
    q.print();
    q.pushBack(8);
    q.print();
    q.pushBack(9);
    q.print();
    }
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What don't you understand? You have to actually write the methods for the class. The names do a good job describing what the method will do.

    Edit: please use code tags, you can edit them in
    [code]
    YOUR CODE HERE
    [/code]

    And ask specific questions, if you get errors, post the exact error in code tags, for logic errors, explain them.
    Last edited by sunde887; 06-05-2011 at 05:31 PM.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Think about what each method should do, come up with a design to do it, write comments for each method describing what it is supposed to do and how it is going to do it.
    Then when the above are done, write the code.

  4. #4
    Veton is offline Member
    Join Date
    Jun 2011
    Posts
    2
    Rep Power
    0

    Default

    This code is written from my teacher.. and i start lessons last week, i dont know what to doo.. can you meet the code plz.. :(

  5. #5
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Give what norm said a shot and see what you come up with. Try your best to compute the easiest methods first and work your way up to the challenging ones. If you run into problems, ask specific questions.

Similar Threads

  1. Troubles,convert C/C++ Code to Java
    By cristianll in forum New To Java
    Replies: 1
    Last Post: 11-15-2009, 02:30 AM
  2. JOptionPane Troubles
    By Tb0h in forum New To Java
    Replies: 4
    Last Post: 08-26-2009, 01:12 PM
  3. Gif decoding/LZW troubles
    By hellochar in forum Advanced Java
    Replies: 2
    Last Post: 07-14-2009, 11:26 PM
  4. Image troubles
    By Theodoreb in forum New To Java
    Replies: 24
    Last Post: 07-14-2009, 12:41 AM
  5. subclass troubles
    By xf021209 in forum New To Java
    Replies: 12
    Last Post: 04-20-2009, 11:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •