OOPS Through Java-CS3702 Lab Manual
OOPS Through Java-CS3702 Lab Manual
Should have the ability to extend his/her knowledge of Java programming further on
his/her own.
Week-I
2. Write a Java program that prints all real and imaginary solutions to the quadratic
equation ax2 + bx + c = 0. Read in a, b, c and use the quadratic formula
6. Write an application that declares 5 integers, determines and prints the largest and
smallest in the group.
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 1
OOPS using JAVA CSE-E3
Week-II
Week-III
1. Write a program to display details of the required employee based on his Id. The
details of employee includes, Emp_name, Emp_age, Emp_gender, Emp_designation,
Emp_salary, Emp_Address etc.,
2. A mail-order house sells five products whose retail prices are as follows : Product 1 :
Rs. 99.90 , Product 2 : Rs. 20.20 , Product 3 : Rs. 6.87 , Product 4 : Rs. 45.50 and
Product 5 : Rs. 40.49 . Each product has Prdouct_Id, Product_Name,
Product_Quantity, Product_Price. Write an application that reads a series of pairs of
numbers as follows :
a) product Id
b) quantity sold your program use a switch statement to determine the retail price for
each product. it should calculate and display the total retail value of all products sold.
3. Write java program that inputs 5 numbers, each between 10 and 100 inclusive. As
each number is read display it only if it’s not a duplicate of any number already read
display the complete set of unique values input after the user enters each new value
4. Write a java program : rolling a pair of dices 10 times [ each attempt should be delayed
by 10000 ms ] and count number Successful attempts. successful attempt : If the pair of
Dice results in same values.
5. Implement the following case study using OOP concepts in Java. E-Book stall :
Every book has Properties which includes : Book _Name, Book_Author, Book_Count ;
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 2
OOPS using JAVA CSE-E3
Every Customer is having properties as : Customer_Id, Customer_Name,
Customer_Address and he can buy Books from E-Book stall. Write a Program which will
display the text book name and the remaining count of text books when a customer
buys a text book.
Week-IV
1.Write an application that uses String method compareTo to compare two strings
defined by the user.
2. Write an application that uses String method equals and equalsIgnoreCase to tests
any two string objects for equality.
3. Write an application that uses String method indexOf to determine the total
number of occurrences of any given alphabet in a defined text.
4. Write an application that uses String method concat to concatenate two defined
strings.
5. Write a Java program to print all vowels in given string and count number of
vowels and consonants present in given string
6. Write an application that finds the length of a given string.
7. Write an application that uses String method charAt to reverse the string.
8. Write an application that finds the substring from any given string using substring
method and startsWith & endsWith methods.
9. Write an application that changes any given string with uppercase letters, displays
it, changes it back to lowercase letters and displays it.
Week-V
2. Write an application that prompts the user for the radius of a circle and uses a method
called circleArea to calculate the area of the circle and uses a method circlePerimeter to
calculate the perimeter of the circle.
3. Write a JAVA program for the following a. Call by value b. Call by object
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 3
OOPS using JAVA CSE-E3
4. Create a class Account with an instance variable balance (double). It should contain a
constructor that initializes the balance, ensure that the initial balance is greater than 0.0.
Acct details: Acct_Name, Acct_acctno, Acct_Bal, Acct_Address.
Create two methods namely credit and debit, getBalance. The Credit adds the amount
(passed as parameter) to balance and does not return any data. Debit method withdraws
money from an Account. GetBalance displays the amount. Ensure that the debit amount
does not exceed the Account’s balance. In that case the balance should be left unchanged
and the method should print a message indicating “Debit amount exceeded account
balance”.
Week-VI
1. Write a Java program to find Area and Circle of different shapes using polymorphism
concept
2. Write a Java program which can give example of Method overloading and overriding
3. Write an application to create a super class Employee with information first name &
last name and methods getFirstName(), getLastName() derive the sub-classes
ContractEmployee and RegularEmployee with the information about department,
designation & method displayFullName() , getDepartment(), getDesig() to print the
salary and to set department name & designation of the corresponding sub-class objects
respectively.
Week-VII
1. Create an abstract class Shape which calculate the area and volume of 2-d and 3-d
shapes with methods getArea() and getVolume(). Reuse this class to calculate the area
and volume of square ,circle ,cube and sphere.
2. Create an abstract class Employee with methods getAmount() which displays the
amount paid to employee. Reuse this class to calculate the amount to be paid to
WeeklyEmployeed and HourlyEmployee according to no. of hours and total hours for
HourlyEmployee and no. of weeks and total weeks for WeeklyEmployee.
5. Create an Interface Fare with method getAmount() to get the amount paid for fare of
travelling. Calculate the fare paid by bus and train implementing interface Fare.
Week-VIII
1. Write a Program to create your own package. Package should have more than two
classes. write a Program that uses the classes from the package.
2. Create a package named org.shapes. Create some classes in the package representing
some common geometric shapes like Square, Triangle, Circle and so on. write a Program
that uses the classes from the package.
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 5
OOPS using JAVA CSE-E3
3. Write a Java program to create package called dept. Create four classes as CSE, ECE,
ME and CE add methods in each class which can display subject names of your respect
year. access this package classes from main class
Week-IX
1. Program for demonstrating the use of throw, throws & finally - Create a class with a
main( ) that throws an object of class Exception inside a try block. Give the constructor
for Exception a String argument. Catch the exception inside a catch clause and print the
String argument. Add a finally clause and print a message to prove you were there.
2. Write a program that shows that the order of the catch blocks is important. If you try to
catch a superclass exception type before a subclass type, the compiler should generate
errors.
3. Write a program to rethrow an exception – Define methods one() & two(). Method
two() should initially throw an exception. Method one() should call two(), catch the
exception and rethrow it Call one() from main() and catch the rethrown
6. Create your own exception class using the extends keyword. Write a constructor for this
class that takes a String argument and stores it inside the object with a String reference.
Write a method that prints out the stored String. Create a try- catch clause to exercise your
new exception.
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 6
OOPS using JAVA CSE-E3
Week-IX
1. Write a program to create MyThread class with run() method and then attach a thread to
this MyThread class object.
2. Write a program where the consumr thread checks the data production status [ is
over or not ] for every 10 ms.
3. Write a Program using Threads to simulate a traffic light. The Signal lights should glow
after each 10 second, one by one. For example: Firstly Red, then after 10 seconds, red
will be put to off and yellow will start glowing and then accordingly green.
4. Write a Program using Threads for the following case study: Movie Theatre To watch
a movie the following process is to be followed, at first get the ticket then show the
ticket. Assume that N persons are trying to enter the Theatre hall all at once, display
their seuence of entry into theater. Note: The person should enter only after getting a
ticket and showing it to the boy.
5. Write a Program using Threads for the following case study: Train Reservation system
To reserve a berth the following process need to be followed, at first check the number of
available berths with the requested berths, if the number of requested berths are less than
or equal to availabe berths then allot berth and print ticket or else display no berths are
available. Assume that N persons are trying to reserve the berth, display their sequence of
reservation status along with the number of available berths. Note : The person can print
ticket only if berth is confirmed.
Week-X
1. Write a program for the following a. display a frame with title MyFrame b. draw a
horizontal line. c. Draw one line perpendicular to other. One line parallel to other.
2. Create an application to display a circle within rectangle and fill different colors in the
circle & rectangle
3. Write an application that displays any string. Choose color from combo box to change
the color of this displayed string and choose its size & type respectively from another two
combo boxes.
4. Write a small application with a default date 01/01/2000 and three combo boxes
displaying valid days, months & year (1990 – 2050). Change the displayed date with the
one chosen by user from these combo boxes.
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 7
OOPS using JAVA CSE-E3
5. Create a GUI with title STUDENT which has labels roll no., name, course, gender, class,
address with textboxes for taking input from the user(without any functionality) and
checkboxes for selecting the course, radio buttons for selecting gender with appropriate
background color.
6. Create a GUI application to display a calculator using grid Layout (You do not have to
provide functionality).
Week-XI
1. Write a program to create a frame by creating an object to Jframe class and include close
button to terminate the application of the frame.
3. Write a program to create a push button , when the button is clicked an image is
displayed in the frame.
5. Create an application Form for University Enroll ment with the following Fields.
a. Check box b. Text area c. List box d. Display text e. Push buttons f. Combo
box. g. Radio buttons. h. Back ground color
Week-XII
3. Create a Form to insert and retrieve the data from Database as user prefer.
5. Write a program to Store and retrieve file content from the Data base.
RGUKT-B.Tech-CSE-OOPS-CS3702-E2-SEM-2-AY:2019-2020. Page 8