//Class Main
import java.util.Scanner; public class Main
{
public static void main() {
int choice, pushValue;
boolean done = false;
Stack stack1 = new Stack();
Scanner keyboard = new Scanner(System.in);
while (!done)
{
System.out.print(”Enter 1 to push, 2 to pop, and 3 to quit: “); choice = keyboard.nextInt();
System.out.println();
switch (choice)
{
case 1:
System.out.print(“Enter an integer to push: “); pushValue = keyboard.nextInt(); stack1.push(pushValue);
System.out.println();
break;
case 2:
System.out.println(“The top value on the stack was: “ + stack1.pop());
System.out.println();
break;
case 3:
done = true;
break;
default:
System.out.println(“The number you entered, “+ choice + “, + is not 1, 2, or 3. Try again!”);
System.out.println(); break;
}
}
System.out.println(“...quitting”); }
}
//Class Stack (assertions go in the blank lines)
public class Stack
{
private int[] stackArray = new int[100];
private int top = 0;
public void push(int pushValue)
{
stackArray[top] = pushValue;
top++;
}
public int pop()
{
top--;
return stackArray[top];
}
}
What I need help with:
-Adding two new methods to class Stack:
isEmpty() // returns true if the stack is empty; false otherwise isFull() // returns true if the stack is full; false otherwise
-Modifying the switch statement in class Main to handle the methods by adding new cases for calling methods isEmpty() and isFull().
-Also modifying the cases in the switch statement that call push() and pop() so that the call is not made to push() if the stack is full and the call to pop() is not made if the stack is empty.
-Including assertions in the class Stack that show that it's correct.
*I'm not looking for answers, but I would love help understanding the concepts that are being asked and how to implement them. I'm still relatively brand new to Java.

New Topic/Question
Reply



MultiQuote





|