01CE0104 ObjectOrientedProgramming LabManual
01CE0104 ObjectOrientedProgramming LabManual
Course Outcomes
CO1 Use the syntax and semantics of java programming language and basic concepts of OOP.
(Remember)
CO2 Analyse the concepts of Inheritance, Interface and Packages in java. (Analyze)
CO3 Apply the concepts of Multithreading and Exception handling to develop efficient and error
free codes. (Apply)
CO4 Understanding the concept of streams and collections to implement java applications. (Apply)
Lab Program CO
1. a. A Demo on NetBeans IDE. CO1
b. Write a Java Program to print “WELCOME TO MEFGI”.
c. Write a Java Program to print Address as follows:
1. Single print statement
2. Multiple print statements
d. Write a Java program to swap two numbers without using a third variable.
e. Write a java program to perform Addition and Subtraction arithmetic operations,
where Variable Input will be taken from the user. (Using Scanner class).
2. a. Write a Java Program to print “HELLO WORLD”. CO1
b. Write a java Program to print Address of Marwadi University:
1. Single print statement
2. Multiple print statements
c. Write a Java program to swap two numbers using a third variable.
d. Write a java program to perform Multiplication, Division and Modulus arithmetic
operations, where Variable Input will be taken from the user. (Using Scanner
class).
3. a. Write a program in java to calculate total, percentage marks of the student, take CO1
marks input from user for 5 subjects.and also Display the grade/division using the
if else statement.
b. Write a Java Program to Count sum and average of all numbers entered by user
using infinite loop. If the number is divisible by 5, the loop should continue ( i.e it
should not be added in sum). If the number is 999 the loop should be terminated
and it will display sum and average both.
4. a. Write a java Program to calculate the Gross salary of an employee and also CO1
calculate the Income tax on the basis of Annual salary of an employee, Basic salary
Input will be taken from the user. Gross Salary = Basic Salary + DA + HRA where DA
= 60% of Basic salary HRA = 25% of Basic salary For Income Tax, if Gross salary
between 3 Lakh to 5 Lakh then ITax= 10% of Annual salary if Gross salary between
5 Lakh to 10 Lakh then ITax= 15% of Annual salary else if Gross salary > 10 lakh then
|1
FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0104 – Object Oriented Programming – Lab Manual
5. a. Write a java program that will print month name of the given number (Using Switch CO1
statement) Eg:- If we are inserting 1 then it should print January .
b. Write a Java Program to multiply two matrices of 3X3.
c. Write a java program to perform following string operations: String length, string
concatenation, compare two string, substring, Replace string.
6. a. Write a java program that will check whether the inserted alphabet is vowel CO1
(a,e,i,o,u,A,E,I,O,U )or not if not vowel then it should display consonant (Using
switch statement)
b. Write a Java Program to find the addition of two matrices of 3X3 and transpose of
that matrix.
c. Write a java program to check whether input string is palindrome or not.
7. Write a JAVA program to create a class Student with data ‘name, city and age’ along CO1
with method printData to display the data. Create the two objects s1, s2 to declare
and access the values.
8. Write a Java Program to create a class Employee with Emp_name, Emp_code and CO1
Emp_sal as a data member. Write a method getdata to accept the data of E1 and E2.
and display the data of the Employee using printdata method.
9. Write a Java Program to create a class Employee with Emp_name, Emp_code and CO1
Emp_sal as a data member. Write a method getdata to accept the data of 5 employees
and display the data of those employees whose salary is greater than 25000 using
printdata method.
10. Write a JAVA program to create a class Student with data ‘name, city and age’ along CO1
with method printData to display the data. Read the data for 5 students and display the
record of those students whose age is greater than 18.
11. Write a java program that creates a class called Person which has the following private CO1
instance variables:- name , age and address . The person class should have a constructor
that takes values for each of these variables and sets them accordingly. The class should
have a finalize() method that prints the message to console indicating that the object
has been destroyed. The main() method should create two instances of the person class
with different values for the instance variables.
12. Write a java program that creates a class called ‘Myclass’ with private instance variable CO1
‘count’. ‘Myclass’ should have a constructor that takes an integer value and sets ‘count’
to that value. ‘Myclass’ should also have a ‘finalize()’ method that decrements count by
1 and prints the value of ‘count’ to the console. In the main() method of the program ,
create two instances of the ‘Myclass’ with different integer values.
13. Write a java Program using parameterized constructor with two parameters id and CO1
name. While creating the objects obj1 and obj2. Pass two arguments so that this
|2
FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0104 – Object Oriented Programming – Lab Manual
constructor gets invoked after creation of obj1 and obj2. Create one method to print
the data.
14. Write a program in JAVA to create a class Bird also declares the different parameterized CO1
constructor to display the name of Birds.
15. a. Define an abstract base class Shape that includes protected data members for the CO1, CO2
(x, y) position of a shape, a public method to move a shape, and a public abstract
method show() to output a shape. Derive subclasses for lines, circles, and
rectangles. You can represent a line as two points, a circle as a center and a radius,
and a rectangle as two points on diagonally opposite corners. Test the classes by
objects of the derived classes, and then invoking the show() method.
b. Create a class bank that provides functionality to get the rate of interest. However,
the rate of interest varies according to banks. For example, SBI, ICICI and AXIS banks
could 8%, 7%, and 9% rate of interest. Override the method getRateOfInterest from
the parent class to all child classes.
16. a. Write a java program in which you will declare an abstract class Vehicle inherits CO1, CO2
this class from two classes car and truck using the method engine in both display
“car has good engine” and “truck has bad engine”.
b. Create a Parent class called ‘Vehicle’ with a method name ‘drive()’. This method
should simply print out the message “Driving the vehicle”. Create a child class
‘Car’ that extends ‘Vehicle’. Override the ‘drive()’ method in ‘Car’ to print out the
message “Driving the car”. In the main() method create an instance of Vehicle
and an instance of Car class. Call the ‘drive()’ method on each object. Program
should output the message printed by each ‘drive()’ method.
17. Write a JAVA Program to create an interface named Polygon. The interface contains an CO1, CO2
abstract method getArea(). Here, the Rectangle class implements Polygon. Using this
abstract method, calculate the area of the rectangle.
18. Write a JAVA Program to create an interface named Polygon. The interface contains an CO1, CO2
abstract method getVolume(). Here, the Rectangle class implements Polygon. Using this
abstract method, calculate the volume of the rectangle.
19. Write a program that will generate exceptions of type NullPointerException, CO1, CO3
NegativeArraySizeException, and IndexOutOfBoundsException. Record the catching of
each exception by displaying the message stored in the exception object.
20. Write a program that calls a method that throws an exception of type CO1, CO3
ArithmeticException at a random iteration in for loop. Catch the exception in the
method and pass the iteration count when the exception occurred to the calling method
by using an object of an exception class you define.
21. Write a Java program that creates three threads. The first thread displays "Good CO1, CO3
Morning" for every one second, the second thread displays "Hello" for every two
seconds and third thread displays "Welcome" for every three seconds.
|3
FACULTY OF ENGINEERING AND TECHNOLOGY
Department of Computer Engineering
01CE0104 – Object Oriented Programming – Lab Manual
22. Write a Java program that creates three threads. The first thread displays "Hiiii" for CO1, CO3
every one second, the second thread displays "Hello" for every two seconds and the
third thread displays "How Are You..?" for every three seconds
23. Write Java Program a main() method that takes the name of a text file as a command CO1, CO4
line argument and prints every line in lower case.
24. Write Java Program a main() method that counts the number of words in a text file CO1, CO4
whose name is accepted from standard input. Also print the size of a file.
25. Write a java program to perform insert, delete and access operations in the ArrayList CO1, CO4
class.
26. Write a java program to perform insert, delete and access operations for Vector class. CO1, CO4
27. Write a java program to perform push and pop operations in the Stack class. CO1, CO4
28. Write a java program to perform put and clear operations in Maps class . CO1, CO4
Software Required
• JDK
• NetBeans-VS Code- Intelli J -Notepad (Any Editor)
|4