Question: Can you help me with writing a code Java for the following requirement? Assessment Requirements Section 1: 1.Enter the comment with the section title as

Can you help me with writing a code Java for the following requirement?

Assessment Requirements

Section 1:

1.Enter the comment with the section title as described above.

2.Print to the console the message, "Assessment 6 - Asserts and Try/Catch."

3.help with string variable and set its value to null or empty.

4.help with integer variable and set it to 0.

5.Note: The variables above are initialized to values intended to triggerthe following assert statements.

6.help with assert statement to validate that the string variable is not empty or null with the message, "Parameter must not be empty or null."

7.help with assert statement to validate that the integer variable is greater than zero with the message, "Parameter must be greater than zero."

Section 2:

1.Enter the comment with the section title as described above.

2.help with array of strings.

3.help with try/catch block.

4.In the try portion of the try/catch, you will loop through the array using a'for loop' where your index variable begins at 0 and the loop continuesas long as the index is <=the length of the array. This will cause anarray out of bounds error where the loop attempts to access an arrayindex value that is one more than the last item.

5.The catch portion will catch the out of bounds exception. Inside thecatch block you will help with two lines to the console. The first simplyprints the string, "Array out of bounds error occurred." On a new lineyou will then print the error message contained in the exception object.

Section 3:

1.Enter the comment with the section title as described above.

2.help with try/catch block.

3.In the try portion of the try/catch, you will attempt to open a non-existent file named, "NoFileNamedThis.txt".

4.The catch portion will catch the file not found exception. Inside the catch block you will help with two lines to the console. The first simplyprints the string, "File not found error." On a new line you will then printthe error message contained in the exception object.

Section 4:

1.Enter the comment with the section title as described above.

2.help with function called, "DivideByZero", which will allow fortwo integer operands, dividend and divisor.

3.The function will check to be sure the divisor is not equal to zero.

4.If the divisor is equal to 0 then the function will throw an exception with the message, "Divide by Zero."

5.help with try/catch block.

6.In the try portion you will call the function, DivideByZero, and pass ittwo numbers with the second being 0 to cause an error.

7.The catch portion will catch the Divide By Zero exception thrown by thefunction. Inside the catch block you will help with two lines to the console.The first simply prints the string, "DivideByZero error occurred." On anew line you will then print the error message contained in theexception object.

EXPECTED OUTPUT

Note:Errormessagesmightdifferfrom languagetolanguageandthefilepathaswell.

Assessment 6 - Asserts and Try/Catch.

(Here the two assert statements should create popup windows informing the user the string is null or empty and the integer should be greater than 0. Choosing to ignore the assertions should allow the program to continue.)

ArrayOutOfBounds error occurred

Index was outside the bounds of the array.

FileDoesNotExist error occurred

Could not find file

'C:\ NoFileNamedThis.txt'

DivideByZero error occurred

Divide By Zero

Program 2

Purpose

The purpose of this program is to provide you with an opportunity to demonstrate your knowledge of exception handling to log exceptions to a log file.

Assessment Requirements

1.Print to the console the following messages:

"Assessment 7 - Logging Exceptionsto a File."

"Testing Try/CatchforDividebyZero,FileDoesNot Exist,ArrayOutofBounds,andArrayisNullscenarios."

"Allconsoleerrormessagesareprintedfromerrorlog file."

1.Createalogfile.RedirectthestdErrstreamtowritetoyourlogfile.

2.Createafunction,DisplayLogfile(),thatwillreadthelogfileanddisplaytotheconsole.

3.write function named, DivideByZero(), which will attempt to divide anumber by 0.

4.write function named, FileDoesNotExist(), which will attempt toopen a non-existent file named, "NoFileNamedThis.txt".

5.write function named, ArrayOutOfBounds(), which will create anarray and then try to access a non-existent index in that an array.(Hint:If there are 5 items in the array then the code might try to access item6 for instance.)

6.help with function named ArrayIsNull(), which will create an array andthen set it equal to null before trying to access an item in the array.

7.help with try/catch block.

8.From the try portion, call the function, DivideByZero().

9.In the catch portion, write the error message contained in the exception object to the standard error stream.

10.Help with try/catch block.

11.From the try portion, call the function, FileDoesNotExist().

12.In the catch portion, write the error message contained in theexception object to the standard error stream.

13.Create a try/catch block.

14.From the try portion, call the function, ArrayOutOfBounds().

15.In the catch portion, write the error message contained in theexception object to the standard error stream.

16.Create a try/catch block.

17.From the try portion, call the function, ArrayIsNull().

18.In the catch portion, write the error message contained in theexception object to the standard error stream.

19.Call the DisplayLogFile() function to display the contents of the log fileyour program has created.

20.

EXPECTED OUTPUT

Note: Error messages might differ from language to language and the filepath as well.

Assessment 7 - Logging Exceptions to a File.

TestingTry/CatchforDividebyZero,FileDoesNot Exist,ArrayOutofBounds,andArrayisNullscenarios. Allconsoleerrormessagesareprintedfromerrorlog file.

Attempted to divide by zero.

Could not find file 'C:\NoFileNamedThis.txt'

Index was outside the bounds of the array.

Object reference not set to an instance of an object.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!