stack class using push and pop methods

I am new to programming Java, and I have an assignment where I have to create a stack class that stores the first 50 numbers(0-50). I also have to use the push and pop method.

I am not 100% sure how to set this up. This is what I have so far. The thing I can't figure out is where to use the push and the pop.

package stack;

import java.util.*;

/**

*

* @author ppaparie

*/

publicclass Main{

/** Creates a new instance of Main */

public Main(){

}

/**

* @param args the command line arguments

*/

class Stack{

publicstaticvoid main(String[] args){

// TODO code application logic here

Stack stack =new Stack();

for(int i= 1; i <= 50; i++)

}

}

}

[1524 byte] By [paps33a] at [2007-11-27 10:25:46]
# 1

Create a class variable called ArrayList arrayList=new ArrayList();

Create a function called void push(String x1)

Create a function called String pop();

In the push function, add x1 to the array,

in the pop function, return the last item you added to the array and before returning its value, remove it from the array.

The challange is, you have to retreive the lastest item to be stored in the array, and remove the lastest item that was stored in the array. Also, is arrayList the appropriate collection to use. Also, what happens if you pop more items out of the arrayList that was put in.

The key in the assignment is the phrase "use a push and pop method'. There is no push and pop method in java, you have to create them.

George123a at 2007-7-28 17:35:33 > top of Java-index,Java Essentials,Java Programming...