0% found this document useful (0 votes)
30 views1 page

Exercise 1:: Java Assignment 4

The document contains instructions for three Java programming exercises. The first involves handling a NullPointerException, the second involves handling errors with an object array, and the third involves validating user input for a Person object and throwing custom exceptions if validation fails.

Uploaded by

Nagaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views1 page

Exercise 1:: Java Assignment 4

The document contains instructions for three Java programming exercises. The first involves handling a NullPointerException, the second involves handling errors with an object array, and the third involves validating user input for a Person object and throwing custom exceptions if validation fails.

Uploaded by

Nagaraj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Classification: Internal

JAVA ASSIGNMENT 4

Exercise 1:

Program to Handle NullPointerException

a) create class Person with method display()


Which displays message ‘I am fine”

b) Create class PersonTest with main entry point


c) In main method handle NullPointerException for Peron object creation
d) If an object is not crated properly then handle the exception
e) Print message “problem in creating person object”

Exercise 2:

a) Create class Person with name and age properties with getter/setter
b) Create PesonTest class having main method
c) In main method create an object array of Person and handle the appropriate error
d) If object array is used beyond its limit, then print exception message
“array can .t be used below or above its limit “and terminate the program
e) If no exception, then print person details

Exercise 3:

a) Create class Person having properties name, city, age, phono


b) Add Getter/setter method for the properties
c) Create Person Test class with main method
d) Take input from user for person details
e) Check the following condition
1. Name entered should be max 15 character
2. If name exceed 15 character, then throw an exception on this condition
3. Print message “name should be of max 15 character” and terminate the program
f) City entered should be “pune” , “Mumbai” or “Chennai”
If user enter any other city throw an exception message
“Please enter city (pune|Mumbai|Chennai) only” and terminate the program
g) Phone number enter should be 10 digits
Else throw and exception message “enter valid 10-digit number” and terminate the program
h) For correct input display the person details

You might also like