User Profile

Collapse

Profile Sidebar

Collapse
c0426
c0426
Last Activity: Nov 6 '08, 12:26 AM
Joined: Nov 3 '08
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • c0426
    replied to Exceptions
    in Java
    ah perfect! Thank you so much!
    See more | Go to post

    Leave a comment:


  • c0426
    replied to Exceptions
    in Java
    [CODE=java]import java.util.*;
    public class Stack
    {
    private Object stk[];
    private int top;


    public Stack()
    {
    stk= new Stack[50]; //creates a default setting of 50 objects in the stack.
    top= -1; //sets top of stack to -1 to show there is no objects in the stack yet.

    }

    public Stack(int size)...
    See more | Go to post
    Last edited by r035198x; Nov 5 '08, 07:28 AM. Reason: added code tags. Please don't forget them next time.

    Leave a comment:


  • c0426
    replied to Exceptions
    in Java
    Oh Jos, I understand what you are saying. The goal of the assignment though is to utilize a try/catch block for an exception that is thrown. So I am supposed to handle the EmptyStackExcep tion using the try/catch block. I just don't see how this is possible if the complier will not allow me to pass a message in the exception's parameters.
    See more | Go to post

    Leave a comment:


  • c0426
    replied to Exceptions
    in Java
    r, my pop method is as follows.
    public Object pop() // Removes and returns object at top of this stack. Throws an EmptyStackExcep tion if the stack is empty
    {
    if( top == -1 )
    {
    throw new EmptyStackExcep tion();
    }
    return stk[top--];

    }

    Jos,
    are you implying that I should put the while loop in the try/catch block?

    Thank you both!
    See more | Go to post

    Leave a comment:


  • c0426
    started a topic Exceptions
    in Java

    Exceptions

    Hello all! I'm relatively new to Java, so I'm sorry if this question comes off as naive. I am creating an array-based stack class. The goal of it is to work on exceptions.

    I have 2 classes, a test class and a regular class. The regular class has the methods object peek(), object push(), and object pop(). For the peek and the pop methods I am using an EmptyStackExcep tion. For some reason, the EmptyStackExcep tion will not allow me...
    See more | Go to post
No activity results to display
Show More
Working...