Answered step by step
Verified Expert Solution
Link Copied!

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.
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
}
}
}
image text in transcribed
image text in transcribed
Input format Your program should read from standard input (i.e. System.in). It will write to standard output (i.e. System.out). This is the way ALL of our projects will be, unless otherwise indicated. Each input will consist of one trace. Each line of input will contain either a call or a return, followed by a space, followed by the name of the function. The name of the function may not contain whitespace. When comparing two function names to see if they match, case IS important. 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

Discuss the process of behavior modeling training.

Answered: 1 week ago

Question

what is a peer Group? Importance?

Answered: 1 week ago