Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You should use the .java file provided here, modify it appropriately, and upload your solution. You may modify anything you like, but it has a
You should use the .java file provided here, modify it appropriately, and upload your solution. You may modify anything you like, but it has a basic structure you can follow.
Program output Here are the outputs your program may produce: Valid trace Maximum call depth was DEPTH for valid traces, and the output of Invalid trace at line LINENUMBER followed by one of the following: Returning from FUNCTION1 instead of FUNCTION2 Returning from FUNCTION which was not called Not all functions returned followed by a stack trace. The difference between the first two errors is whether any functions are on the stack. See (and use) the executables below for details. Your program should produce only one of these statements per document. In addition, if the trace is invalid, your program should produce the stack trace (the functions on the stack when the error is detected), one line per function. If there are multiple errors, print only the first one detected (earliest in the input). The terms in all-caps are defined as follows: DEPTH: the number of items on the stack LINENUMBER: the line number of the input (where the error is detected) FUNCTION1, FUNCTION2, FUNCTION: names of functions (FUNCTION1 is the function that is trying to return, while FUNCTION2 is the function on top of the stack) import java.util.Scanner;
import java.util.Stack;
public 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
Stack callStack = new Stack();
// 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;
while (input.hasNext()) {
line = input.nextLine();
lineNumber++;
System.out.println(line);
// PUT YOUR CODE HERE
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started