Sir attached is what i have so far, i worked on this for about an hour, i think ive almost got it but still unsure about how to read in 80 char's. I appreciate your feedback, as i am sure that everyone finds this amusing but i am in my first year of CS and need some direction.
Heath
--- On Mon, 1/18/10, harrybeezhold <harrybeezhold@
From: harrybeezhold <harrybeezhold@
Subject: [Java] Re: can someone help me on a school assignment
To: Java_Official@
Date: Monday, January 18, 2010, 10:45 PM
I could write this program in less than a half hour.
However, that's not what this group is about.
Rather, show us what you have thought / designed / coded / tested or whatever.
Then we can discuss particular stumbling blocks.
Here is part of what I mean:
What objects do you see?
What characteristics( properties) does each object have?
What behaviors(methods) does each object have?
Hint
I see two objects:
1 FlipStack
properties
the stack (some kind of array)
the next position (for the next char)
methods
initialize
push
pop
is it empty
2 FlipStackTestDriver
properties
a FlipStack
methods
main
instantiates the FlipStack,
some kind of loop
push one byte
another loop
pop one byte
display results
Try coding that. If you get stuck, come on back, but be specific.
Note this can all be done in one class by moving the main method into the FlipStack class. Also, if you do it with two classes, you might want to ask your instructor which class he'd like to have do the popping and display.
--- In Java_Official@ yahoogroups. com, "h.graham13" <h.graham13@ ...> wrote:
>
> I need someone to show me how to implement the standard stack procedures (push, pop, and isempty) using an array. They will be called by a driver which accepts up to 80 characters at a time, places each character on the stack, and, once finished receiving characters, then displays them in reversed order. I am not allowed to use any built-in functions. Any help would be greatly appreciated.
>
----------
public class Stack<T> {
private T[] items;
private int top;
@SuppressWarnings(
public Stack(int size) {
items = (T[]) new Object[size]
top = -1;
}
public void push(T item) throws Exception {
if (top == items.length - 1)
throw new Exception("Stack Full");
items[++top] = item;
}
public T pop() throws Exception {
if (top == -1)
throw new Exception("Stack Empty");
return items[top--]
}
}
[Non-text portions of this message have been removed]
Java Official Group is created for the following topics: Java 2 Enterprise Edition - J2EE, Java 2 Standard Edition - J2SE, Java 2 Micro Edition - J2ME, XML, XSL, XSD, XPATH, Web Services, Jini, JXTA for all type of Java Geeks.
Whoever posts spam / ads / job related message will be BANNED IMMEDIATELY
No comments:
Post a Comment