Preciso de ajuda a resolver o seguinte exercicio em java.
Isto é para um trabalho escolar, eu penso que seja simples mas sou novato em java e nao estou entendendo o que me é pedido para fazer.
Por favor alguem me ajude.
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)
Isto é para um trabalho escolar, eu penso que seja simples mas sou novato em java e nao estou entendendo o que me é pedido para fazer.
Por favor alguem me ajude.
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)