Beruflich Dokumente
Kultur Dokumente
Exercise 1
David is assigned a task of creating a Application to store Employee details. For this David decides
to display the following menu when the Application starts.
1. Enter Data.
2. Display Data
3. Exit
Lab steps:
1. Open the Netbeans. Create a new
project chapter09_ex1.
if (c != 'e') {
throw new PatternException();
}
employeeDetails[i][0] = empid;
System.out.println(employeeDetails[i][j]);
}
}
7. Create the method exitMenu to exit the public void exitMenu() {
Application System.exit(0);
}
8. Coding the main method. int flag = 0;
EmployeeDetails obj = new EmployeeDetails();
do {
flag = 0;
{
try {
obj.showMenu();
} catch (SelectionException Obja) {
System.out.println("Exception caught: "
+ Obja);
}
Lab Steps:
3. Add a new class to the project NewAxis. static void showAge(int mage) throws
a. Add data members to the class name and SelectionException {
contactno of string type. Age for Integer if ((mage < 18) || (mage > 55)) {
throw new SelectionException();
type.
}
b. Create scanner class object to accept the }
details for the user. public void form() {
c. Create a static method showAge taking a System.out.println("*******Disco
int parameter and throws the Registration Form*******");
selectionException. System.out.println("Enter the name: ");
d. If the age accepted is not between 18 name = details.nextLine();
System.out.println("Enter the contact
and 55 throw the selectionException
number: ");
e. Create a method form to accept the contactno = details.nextLine();
details line contactno
System.out.println("Enter the age: ");
age = details.nextInt();
try {
showAge(age);
} catch (SelectionException Obja) {
}
}
4. Coding the main method in NewAxis. NewAxis obj1 = new NewAxis();
a. Create a object of NewAxis and call
the method form. obj1.form();
Lab Steps:
1. Create a new Java Application name it as
chapter09_ex3
2. Create a class named CalculatorApp.
5. Test
Case 1: Input negative numbers
Case 2: Input positive numbers
Objective: To handle Divide by zero Exception
Lab Steps:
Happy Learning!!