Oop A Section Questions

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

CS2002-1(OOP) LAB SESSIONAL ‘A’ SECTION

Part A

1. Build a program called “GuessMyNumber”. The computer will generate a random number
between 1 and 10. The user types in a number and the computer replies “lower” if the random
number is lower than the guess, “higher” if the random number is higher , and “correct!” if the
guess is correct. The player can continue guessing until the guess is right.

2. Write a java program to create two separate arrays of integers. Elements of both the arrays shall
be read from keyboard input. Program should display “Arrays are symmetrical” if both the arrays
contain equal numbers of even and odd numbers.

3. Create a Java class called Student with the following details as private instance variables within
it.
USN
Name
Branch
Phone
Write a Java program to create n number Student objects and print the USN, Name, Branch, and
Phone of these objects with suitable headings.

4. Design a super class called Staff with details as StaffId, Name, Phone, Salary. Extend this class
by writing three subclasses namely (Hieriarchical inheritance) Teaching (domain, publications),
Technical (skills), and Contract (period). Write a Java program to read and display at least 3 staff
objects of all three categories.

5. Write a program to generate the resume. Create 2 Java classes Teacher (data: personal
information, qualification, experience, achievements) and Student (data: personal information,
result, discipline) which implements the java interface Resume with the method biodata().

6. Write a program to illustrate the order of constructor calling via multilevel inheritance
(illustrate atleast more than 2 levels).

7. Write a Java program that implements a multithreaded application that has three threads. First
thread generates a random integer for every 1 second; second thread computes the square of the
number and prints; third thread will print the value the cube of the number.

8. Develop a multithreaded java program to demonstrate synchronization of a method. The


method is going to print the message passed by three child thread instances by embedding square
braces onto it. e.g [Message].The messages “Learn”, “Java”, “Programming” are passed to the
method by three instances of child threads respectively. Show the possible outputs with and without
synchronization of method.

9. Write a program to count the number of capital letters, display the position of each capital letter ,
no; of digits and no: of occurrences of each vowel in a user entered string via keyboard.

10. Write a program that will count the number of characters, words, and lines in a file. Words are
separated by a white-space character. Your program should prompt the user to enter a filename.
Part B

1. Develop an abstract class called Shape having two data members base and height of type
double. Derive three specific sub-classes Triangle, Circle and Rectangle from the base Shape. Add
to the base class Shape, a relevant constructor to initialize base class data members and a method
computeArea() to compute and display the area of figures. Make computeArea() as an abstract
method and define this method in the sub-classes to compute area specific to each of the sub-
classes. (Area of Triangle=0.5*base*height, Area of Rectangle=base*height and Area of
Circle=pi*radius*radius).

2. Develop a java program to validate the USN value entered by the user by making use of user
defined exception handling concept.Valid usn number will have the format “NNMmmXYnnn”
where mm is numeric value ranging from 01 to 23 , valid values for XY are
“CS”,”CV”,”AI”,”EE”,”EC”,”ME”,”RE”,”BT”,”IS”,”CC”,”DS” and nnn is running 3 digit
number.The exception message will be “Invalid USN”,”Invalid Year”,”Invalid branch
code”,”Invalid Running number” dependending on the error in the value entered.

3. Write a Java program to read n number of integers into an array. Raise an appropriate exception
(ArithmeticException, InputMismatchException, NumberFormatException,
ArrayIndexOutOfBoundsExcception)while performing following operations; a) Dividing each
element by the smallest element in an array. b) reading elements from the keyboard c) accessing the
element from the index specified by the keyboard entry d) parsing string to numeric form. Concept
of exception handling using multiple catch blocks to be used in this scenario.

4. Write a java program that reads a file name from the user, displays information about it to
demonstrate following methods of class File.
canRead()
canWrite()
delete()
exists()
getPath()
getAbsolutePath()
length()
list()
mkdir()

5. Develop a java application to implement distance converter (meter to KM, miles to KM and vice
versa), time converter (hours to minutes, seconds and vice versa) using packages.

6. Demostrate mouse events (8 events) handling using AWT based GUI java application.

7. Demostrate keyboard events (3 events) handling using AWT based GUI java application.

You might also like