Java
Java
Topics
No. Hands-on Assignment Status
Covered
A library needs to develop an online application for
two types of users/roles, Adults and children. Both of
these users should be able to register an account.
registerAccount function:
if age > 12, a message displaying “You have
successfully registered under an Adult Account” should
be displayed in the console.
If age<12, a message displaying, “Sorry, Age must be
greater than 12 to register as an adult” should be
displayed in the console.
requestBook function:
if bookType is “Fiction”, a message displaying “Book
Issued successfully, please return the book within 7
days” should be displayed in the console.
Else, a message displaying, “Oops, you are allowed to
take only adult Fiction books” should be displayed in
the console.
6. Create a class “LibraryInterfaceDemo.java” with a
main method which performs the below functions,
Age
10
18
BookType
“Kids”
“Fiction”
Age
5
23
Set the book Type as specified in the below table and
invoke the requestBook method of the AdultUser
object
BookType
“Kids”
“Fiction”
Topics
No. Hands-on Assignment Status
Covered
Create a package called test package;
Define a class called foundation inside the test
package;
Inside the class, you need to define 4 integer
variables;
Var1 as private; Packages
Var2 as default;
1 Var3 as protected; Access control
Var4 as public; Using package
Import this class and packages in another class.
Try to access all 4 variables of the foundation class
and see what variables are accessible and what are not
accessible.
Topics
No. Hands-on Assignment Status
Covered
Handle exception in number
Problem statement:
Get the input String from user and parse it to
integer, if it is not a number it will throw number
format exception Catch it and print "Entered input is
not a valid format for an integer." or else print the
square of that number. (Refer Sample Input and
Output). Exception
1 Sample input and output 1: Handling
Enter an integer: 12
The square value is 144
The work has been done successfully
Sample input and output 2:
Enter an integer: Java
Entered input is not a valid format for an integer.
Write a program that takes as input the size of the
array and the elements in the array. The program then
asks the user to enter a particular index and prints
the element at that index.
This program may generate Array Index Out Of Bounds
Exception. Use exception handling mechanisms to handle
this exception. In the catch block, print the class
name of the exception thrown.
Sample Input and Output 1:
Enter the number of elements in the array
3
Enter the elements in the array
20
90
4
Enter the index of the array element you want to Exception
2 access Handling: Try-
2 catch
The array element at index 2 = 4
The array element successfully accessed