CST8132 Lab8 Access Array Exercise

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

Warmup Exercises
Write a program that allows a user to input integer values into a 10-element array and search the array.
The program should allow the user to retrieve values from the array by index or by specifying a value to
locate. The program should handle any exceptions that might arise when inputting values or accessing
array elements. The program should throw a NumberNotFoundException if a particular value cannot be
found in the array during a search. If an attempt is made to access an element outside the array bounds,
catch the ArrayIndexOutOfBoundsException and display an appropriate error message.
Required Output
==>sending array test1
Invalid number
==>sending array test2
Array out of bounds
==>sending array test3
==>index for: aaa
Invalid number
==>index for: 12
Number not found
==>index for: 4
4, index: 3
==>value for: aaa
Invalid number
==>value for: -1
Array out of bounds
==>value for: 5
index 5:6

Provided source Code
The following java code is provided in lab7.zip
– ArrayAccessIf.java
– ArrayAccessTest.java
– NumberNotFoundException.java
Instructions
The following is the recommended steps for this assignment:
– Create a package called “lab7”, and copy all the files from lab7.zip.
– Create ArrayAccess class that implements ArrayAccessIf.
– Implement the methods in ArrayAccess as described in ArrayAccessIf.
– Implement printing messages as per “Required Output”.
– If you are printing in try block, use “System.out” stream.
– If you are printing in catch block, ensure you use “System.err” stream.
– Run the provided ArrayAccessTest.java – and compare with required result.
Problem-Solving Tips
1. When you search the array for a value, you should define a boolean value at the beginning of the try
block and initialize it to false. If the value is found in the array, set the boolean value to true. This will
help you determine whether you need to throw an exception due to a search key that is not found.
4. If you have any questions as you proceed, ask your lab instructor for assistance.
Follow-Up Activity
1. Create a copy of your project (highlight the project in Eclipse and ctrl-C ctrl-V), and in the copy, create
another exception class called DuplicateValueException that will be thrown if the user inputs a value
that already resides in the array. Modify the copy your lab exercise solution to use this new exception
class to indicate when a duplicate value is input, in which case an appropriate error message should be
printed. During your demonstration, your lab instructor may ask to see either the original solution, or
the modified copy.