Results 1 to 2 of 2
  1. #1
    ephem is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default structuring the program

    Hi im new to java and trying to write my first program (using stacks).

    Im somewhat confused about how to structure the program. Im use to using a modular language similar to pascal.

    So im trying to implent a stack and operations associated (constructors, observers, modifiers).

    Pop, Push Isempty etc...

    Firstly i need to create a new stack. Will this be my Class?

    The operations associated need to be there too (im use to writing procedures for each operation, within one module). Im unsure about how to pass numbers or objects to be inserted into the empty stack - how to initialise it and where.

    Could somewhat just outline the structure they would expect to use (not so much code but layout).

    thanks

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    I copied the methods from the Stack class spi.
    Java Code:
    public class TestMyStack {
        public static void main(String[] args) {
            MyStack stack = new MyStack();
            stack.push(new E());
        }
    }
    
    class MyStack {
        public MyStack() {
    
        }
    
        // Tests if this stack is empty. 
        public boolean empty() {
    
        }
    
        // Looks at the object at the top of this
        // stack without removing it from the stack. 
        public E peek() {
    
        }
    
        // Removes the object at the top of this
        // stack and returns that object as the
        // value of this function. 
        public E pop() {
    
        }
    
        // Pushes an item onto the top of this stack. 
        public E push(E item) {
    
        }
    
        // Returns the 1-based position where an
        // object is on this stack.
        public int search(Object o) {
     
        }
    }

Similar Threads

  1. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  2. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  3. a few questions on structuring my program...
    By sdkevinb in forum New To Java
    Replies: 0
    Last Post: 02-06-2008, 06:48 AM
  4. Replies: 0
    Last Post: 10-04-2007, 09:33 PM
  5. I need help with this program
    By Daniel in forum Advanced Java
    Replies: 2
    Last Post: 07-04-2007, 05:14 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
  •