Question: import java.util.Scanner; public class PoD { public static void main( String [] args ) { Scanner in = new Scanner( System.in ); Stack computerTasks =

 import java.util.Scanner; public class PoD { public static void main( String[] args ) { Scanner in = new Scanner( System.in ); Stack

import java.util.Scanner;

public class PoD {

public static void main( String [] args ) { Scanner in = new Scanner( System.in );

Stack computerTasks = new Stack();

boolean quitProgram = false;

while (!quitProgram) { String task = in.nextLine(); if (task.equals("quit")) { quitProgram = true; //System.out.println("QUIT"); } else { if (task.equals("undo")) { String undoTask = computerTasks.pop(); //System.out.println("UNDO: "+undoTask); } else { computerTasks.push(task); //System.out.println("DO: "+task); } } } System.out.println(computerTasks);

in.close();

System.out.print("END OF OUTPUT"); } }

import java.util.NoSuchElementException;

public class Stack {

private Node head;

class Node

{

public String data;

public Node next;

}

// Construct an empty stack:

// ================

/**

* Adds an element to the top of the stack

* @param s String to add

*/

public void push(String s) {

// YOUR CODE HERE

// ================

}

/**

* Removes the element from the top of the stack

* @return the removed String

*/

public String pop() {

// YOUR CODE HERE

// ================

}

public String toString()

{

Node position = head;

String output = "";

while (position != null)

{

output += position.data + " ";

position = position.next;

}

return output;

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!