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

![[] args ) { Scanner in = new Scanner( System.in ); Stack](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3115f74861_72766f3115f17660.jpg)
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
Get step-by-step solutions from verified subject matter experts
