Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There were errors. Please fix and resubmit. See below for more details. === Compilation test... > Driver_prj0.java ... file not found >> aborting all tests

There were errors. Please fix and resubmit. See below for more details. === Compilation test... > Driver_prj0.java ... file not found >> aborting all tests 
import java.util.Scanner;
import java.util.Stack;
class Driver_prj0 {
/* main
* parameters:
* args -- the array of command line argument values
* return value: nothing
*
* PUT YOUR COMMENTS FOR THIS FUNCTION HERE
*/
public static void main(String[] args) {
// Here we initialize the scaner variable to read lines of input
Scanner input = new Scanner(System.in);
String line;
// the callStack is used for storing the names of functions that have been
// called and not yet returned
//Adding some elements to stack for testing
Stack callStack = new Stack();
callStack.push("F1");
callStack.push("F2");
callStack.push("F3");
// Each time we go through this while loop, we read a line of input.
// The function hasNext() returns a boolean, which is checked by the while
// condition. If System.in has reached the end of the file, it will return
// false and the loop will exit. Otherwise, it will return true and the
// loop will continue.
int lineNumber = 0;
int maximum_depth = 0;
int flag = 0;
while (input.hasNext()) {
line = input.nextLine();
lineNumber++;
System.out.println(line);
// PUT YOUR CODE HERE
if(callStack.empty()) {
System.out.println("Invalid Trace at line "+lineNumber);
System.out.println("Returning from "+line+" which was not called");
flag = 1;
break;
}
if(!(line.equals((String)callStack.peek()))) {
System.out.println("Invalid Trace at line "+lineNumber);
System.out.println("Returning from "+line+" instead of "+callStack.peek());
flag = 1;
break;
}
callStack.pop();
}
if(flag==0 && callStack.empty()) {
System.out.println("Valid Trace");
System.out.println("Maximum call depth was "+callStack.size());
}
if(flag==0 && !callStack.empty())
System.out.println("Not all functions returned");
if(flag==1) {
System.out.println("Stack Trace:");
while(!callStack.empty())
System.out.println(callStack.pop());
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions