Question: Stack Trace Introduction to exceptions/errors and how to read the descriptive messages indicating these problems. This is called Stack Trace. Complete the STrace.java . Pay
Stack Trace
Introduction to exceptions/errors and how to read the descriptive messages indicating these problems. This is called Stack Trace.
Complete the STrace.java. Pay attention to the comments in the javafile within
To complete the STrace.java, you are to do the following:
Import simple text java.util.*;
Declare Scanner variable (input) and allow user to read a number
Declare two integer variables (data and slot) and assign zero (0) values to the variables iv. Declare an array variable (value) with an integer data type and assign index number of your choice
Compile and run the code. Input values in the data and array index boxes that will trigger the InputMismatchException. And do the following:
IMPORTANT, WORD DOCUMENT 3 LINE EXPLANATIONS OF WHY POINT OF ERROR OCCURED,,, ASWELL AS HOW TO TRACE THE ERROR.
Take a screen shot of your DrJava output console and paste in a Microsoft word doc.
Explain why this error has occurred and how to trace the error (3 lines max.)
Compile and run the code again. Input values in the data and array index boxes that will trigger the IndexOutOfBoundsException. And do the following:
Take a screen shot of your DrJava output console and paste in a Microsoft word doc.
Explain why this error has occurred and how to trace the error (3 lines max.)
Compile and run the code again. Input values in the data and array index boxes that will trigger the ArithmeticException. And do the following:
Take a screen shot of your DrJava output console and paste in a Microsoft word doc.
Explain why this error has occurred and how to trace the error (3 lines max.)
Completed STrace.java and Microsoft word document
Provided to You
These instructions and
Incomplete STrace.java
-------------------------------------------------------------------------------------------------------
STrace.Java
//Place your name and date here //import scanner API public class STrace { public static int division(int data, int slot){ return data / slot; } public static void main ( String[] a ) { /** write your codes here: * Declare scanner variable (input) and allow user to read number * Declare two integer varibales(Check the attached intructions for more details) * Declare an array variable(Check the attached intructions for more details) * */ try { System.out.print("Enter the data: "); data = input.nextInt(); System.out.print("Enter the array index: "); slot = input.nextInt(); value[slot] = data; double result = division(data, slot); System.out.printf("%n%s: %.02f%n", "Result:", result); } catch (InputMismatchException ex ) { System.out.println("Problem occured!!!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } catch (IndexOutOfBoundsException ex ) { System.out.println("Problem occured!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } catch (ArithmeticException ex ) { System.out.println("Problem occured!!!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } System.out.println("Bye-bye" ); } } //Place your name and date here //import scanner API public class STrace { public static int division(int data, int slot){ return data / slot; } public static void main ( String[] a ) { /** write your codes here: * Declare scanner variable (input) and allow user to read number * Declare two integer varibales(Check the attached intructions for more details) * Declare an array variable(Check the attached intructions for more details) * */ try { System.out.print("Please enter the data: "); data = input.nextInt(); System.out.print("Please enter the array index: "); slot = input.nextInt(); value[slot] = data; double result = division(data, slot); System.out.printf("%n%s: %.02f%n", "Result:", result); } catch (InputMismatchException ex ) { System.out.println("This is the problem you just CREATED!!!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } catch (IndexOutOfBoundsException ex ) { System.out.println("This is the problem you just CREATED!!!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } catch (ArithmeticException ex ) { System.out.println("This is the problem you just CREATED!!!: " + ex.getMessage() + " Here is where it happened: "); ex.printStackTrace(); } System.out.println("Good-bye" ); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
