Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By jim829

Thread: I need your help about "Write constructors to MyStack class"

  1. #1
    mervesarikaya is offline Member
    Join Date
    Jan 2015
    Posts
    2
    Rep Power
    0

    Question I need your help about "Write constructors to MyStack class"

    MyStack class have by default some fixed size of maximum elements, please allow user of your class to specify in constructor what this maximum size is. Also please add posibility to specify name of the stack in constructor. User can either create object without parameters, can specify only size or name, or both of them.
    Please also override function toString(), that this code will print:
    [stack1] 4 6 1
    [stack2] empty

    MyStack s1 = new MyStack("stack1");
    MyStack s2 = new MyStack("stack2");
    s1.push(4);
    s1.push(6);
    s1.push(1);
    System.out.println(s1.toString());
    System.out.println(s2.toString());

    You will need in total 5 constractor:
    default constructor (new Stack())
    1-parameter constructor precising maximum size of the stack (new Stack(10))
    1-parameter constructor giving the stack name (new Stack("My Stack"))
    2-parameter constructor giving the maximum size and the name of the stack (new Stack("My Stack", 10))
    "copy" constructor (Stack s1=new Stack(); Stack s2=new Stack(s1);)


    Thanks for help :)

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: I need your help about "Write constructors to MyStack class"

    Do you have a question?

    Regards,
    Jim
    mervesarikaya likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: I need your help about "Write constructors to MyStack class"

    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    mervesarikaya is offline Member
    Join Date
    Jan 2015
    Posts
    2
    Rep Power
    0

    Default Re: I need your help about "Write constructors to MyStack class"

    Yes,I have. This is my homework in my java application. I tried to do something but ıt is not enough.Written requests want my lecturer.
    explanatory few examples enough for me of course .. Thank you.

    Regards,
    Merve

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: I need your help about "Write constructors to MyStack class"

    You need to post your code and ask specific questions about the problems you are having. And be specific.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Multiple Constructors without using "this"
    By tcms in forum New To Java
    Replies: 4
    Last Post: 06-04-2013, 08:36 PM
  2. Replies: 0
    Last Post: 12-07-2012, 08:29 AM
  3. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  4. Replies: 11
    Last Post: 08-18-2011, 10:54 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

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