Question: In this program assignment, you will construct two different exception classes: ClassNotFoundException and ObjectNotFoundException. A static method search that takes an array of objects and

In this program assignment, you will construct two different exception classes: ClassNotFoundException and ObjectNotFoundException.

A static method search that takes an array of objects and a target object as arguments and throws two types of exceptions must be defined. An object of ClassNotFoundException should be thrown if the array doesnt contain an object which is from the same class as the target; if the array contains an object which is the same type of the target but an object with same values as the target cant be found in the array, an object of ObjectNotFoundException should be generated; otherwise the method should return the index of the first occurrence of the target object.

For example, let AO be the array in next paragraph, if D is a Double and I is an Integer with a value of 25, search(AO, D) will throw a ClassNotFoundException and search(AO, I) will throw an ObjectNotFoundException. search(AO, hello) should return 2.

In your main method, an array of Objects AO should be created, including 6 items:

Class Value

Integer 5

Integer 42

String hello

String there

Person Laura 40

Person Peter 35

Also in your main method, try to search the following:

Integer 5

Person steve 5

Double 42

Note: Operator instanceof can be used to check if an object is a member of certain class. Or the method getClass can be used to check the class identity of an object. You should also implement a class Person whose member variables are:

String name;

int age;

A Person object equals another if and only if the two objects have the same name and age. Please override equals method for user defined classes.

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 Databases Questions!