0% found this document useful (0 votes)
3 views

Programming Assignment VII

The document outlines an assignment focused on Thread and Exception Handling in Java. It includes tasks such as creating threads for printing even and odd numbers, implementing custom exceptions for age validation and value searching in arrays, and handling salary data in an Employee class. Additionally, it requires the implementation of a method to check for vowels in a string with appropriate exception handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Programming Assignment VII

The document outlines an assignment focused on Thread and Exception Handling in Java. It includes tasks such as creating threads for printing even and odd numbers, implementing custom exceptions for age validation and value searching in arrays, and handling salary data in an Employee class. Additionally, it requires the implementation of a method to check for vowels in a string with appropriate exception handling.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment-7

Thread & Exception Handling

1. Write a JAVA program that demonstrates the creation and execution of three separate
threads. Each thread should have a unique task:
 Thread 1: Print all even numbers from 1 to 20.
 Thread 2: Print all odd numbers from 1 to 20.
 Thread 3: Print the squares of numbers from 1 to 20.

Ensure that the threads execute independently and then output from each thread is
interleaved.

2. Modify the above program by setting different priority values to the different threads
and observe the output (at least for 5 runs)
3. Design a custom exception class InvalidAgeException that extends Exception. Write
a program where users enter their age during registration process:
a. If the user enters an age below 18, throw an InvalidAgeException with a
message “Age must be 18 or above to register”.
b. Catch the exception and display the error message to the user.
4. Write a program that initializes a 2D array of Integers.
a. Prompt the user to input a value to search for in the array.
b. If the value is not found, throw a custom exception ValueNotFoundException
with a message “Value not found in the Array”.
c. Handle the exception and allow the user to search again.
5. Create a class Employee with attributes name, employeeID and monthlysalaries (an
array containing salaries for 12 months).
a. Create a method calculateAnnualSalary( ) that calculates the total annual
salary.
b. Throw a custom exception SalaryDataMissingException if any month’s
salary is missing or invalid.
c. Handle the exception in the main method and allow the user to correct the data.
6. Write a program in Java that defines a method checkVowel(String str) which checks
if the string contains vowels or not and if not, then throws a custom exception
NoVowelException with message “String does not contains Vowel.”

You might also like