Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Easy Java programming: FILL IN MISSING CODE in the specified areas to achieve the Sample Program Dialogue. (or close to it) TAKE SCREENSHOT OF THE

Easy Java programming:

FILL IN MISSING CODE in the specified areas to achieve the Sample Program Dialogue. (or close to it)

TAKE SCREENSHOT OF THE Compiled Output.

Add a private Random object named r to the ProblemX2 class

Validate the value of x using two assert-statements, (1) check condition #1 (1 assertion; and (2) separately check condition #2 (x

Add a personalized version of lines 9-26 of Figure 11.6 (shown below) to the body of the MyStackTrace() method.

image text in transcribed

//-------------------------------------------------------

// Chapter #11, Extra Problem #2

// ProblemX2.java

//-------------------------------------------------------

import java.util.Scanner;

import java.util.Random;

//---------------------------------------------------------

public class ProblemX2

//---------------------------------------------------------

{

Student defines the Random object r here.

//---------------------------------------------------------

public static void main(String[] args)

//---------------------------------------------------------

{

Scanner IN = new Scanner(System.in);

System.out.print("x [1-4+]? ");

while ( IN.hasNext() )

{

int x = IN.nextInt();

Student writes two assertions here, la (in the style of) Figure 11.8, to ensure (1

try

{

Method1(x);

}

catch ( Exception object )

{

MyStackTrace(object);

}

finally

{

System.out.println("finally clause executed");

}

System.out.print(" x [1-4+]? ");

}

}

//-------------------------------------------------------

public static void Method1(int x) throws Exception

//-------------------------------------------------------

{

try

{

if ( (r.nextInt(4)+1) == x )

{

System.out.println("Method1() did throw-ing");

throw new Exception("Method1() did throw-ing");

}

else

Method2(x);

}

catch ( Exception object )

{

System.out.println("Method1() did rethrow-ing");

throw new Exception("Method1() did rethrow-ing");

}

}

//-------------------------------------------------------

public static void Method2(int x) throws Exception

//-------------------------------------------------------

{

try

{

if ( (r.nextInt(4)+1) == x )

{

System.out.println("Method2() did throw-ing");

throw new Exception("Method2() did throw-ing");

}

else

Method3(x);

}

catch ( Exception object )

{

System.out.println("Method2() did rethrow-ing");

throw new Exception("Method2() did rethrow-ing");

}

}

//-------------------------------------------------------

public static void Method3(int x) throws Exception

//-------------------------------------------------------

{

try

{

if ( (r.nextInt(4)+1) == x )

{

System.out.println("Method3() did throw-ing");

throw new Exception("Method3() did throw-ing");

}

else

Method4(x);

}

catch ( Exception object )

{

System.out.println("Method3() did rethrow-ing");

throw new Exception("Method3() did rethrow-ing");

}

}

//-------------------------------------------------------

public static void Method4(int x) throws Exception

//-------------------------------------------------------

{

try

{

if ( (r.nextInt(4)+1) == x )

{

System.out.println("Method4() did throw-ing");

throw new Exception("Method4() did throw-ing");

}

}

catch ( Exception object )

{

System.out.println("Method4() did rethrow-ing");

throw new Exception("Method4() did rethrow-ing");

}

}

//-------------------------------------------------------

public static void MyStackTrace(Exception object)

//-------------------------------------------------------

{

Student provides personalized version of lines 9-26 of Figure 11.6

}

}

image text in transcribed

Sample Program Dialo CCOURSESYCS2323 Codechapterii>java Problemxz x 11-4+120 Exception in thread "main" 1ava.lang.AssertionError at Problemx2.main (Problemx2.java:27) C:NCOURSES CS2 32 3 CodeChapteri1>java roblemxz x [1-4+1? 5 Exception in thread "main" iaya Tang AssertionEox: Assertionx4) failed at Problemx2.main (Problemx2.java:28) C:COURSES CS2323 CodeChapterl1javae Problemx2 x [1-4+1? 1 ethod40 did throw-ing Method4(0 did rethrow-ing Method30 did etenina Method2 did rethrow-in Method1 did rethrow-in ava lang Exception: Methodi did retrw ng at ProblemX2.Methodi (Problemx2.java: 64) at Problemx2.main (Problemx2.java: 32) Problemx2 Problemx2 finallv clause executed Problemx2.java 64 Problemx2.java 32 Methodi main x 1-412 2 finallv clause executed x 1-412 3 Methodi0 did throw-ns Method1) did rethrow-1n ava lang Exception: Methodi did retrw ng at ProblemX2.Methodi (Problemx2.java: 64) at ProblemX2.main (Problemx2.java: 32) Problemx2 Problemx2 finallv clause executed Problemx2.java 64 Problemx2.java 32 Methodi main x 1-4+1?3 Method30 did throw-ing Method3 did rethrow-in Method2 did rethrow-ing Method1 did rethrow at ProblemX2.Methodi (Problemx2.java: 64) at ProblemX2.main (Problemx2.java: 32) Problemx2 Problemx2 finally clause executed Problemx2.java 64 Problemx2.java 32 Method1 main

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_2

Step: 3

blur-text-image_3

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago