Professional Documents
Culture Documents
K.L.N. College of Engineering: Cs8383-Object Oriented Programming Lab Manual
K.L.N. College of Engineering: Cs8383-Object Oriented Programming Lab Manual
K.L.N. College of Engineering: Cs8383-Object Oriented Programming Lab Manual
Dr.G.RAMESH, Professor/IT
Mrs.N.NANDHINI, Asst.Prof./IT
SYLLABUS
CS8383 OBJECT ORIENTED PROGRAMMING LABORATORY L T P C
0 0 4 2
OBJECTIVES
To build software development skills using java programming for real-world applications.
LIST OF EXPERIMENTS
1. Develop a Java application to generate Electricity bill. Create a class with the following
members: Consumer no., consumer name, previous month reading, current month reading,
type of EB connection(i.e domestic or commercial). Compute the bill amount using the
following tariff.
If the type of the EB connection is domestic, calculate the amount to be paid as follows:
If the type of the EB connection is commercial, calculate the amount to be paid as follows:
2. Develop a java application to implement currency converter (Dollar to INR, EURO to INR,
Yen to INR and vice versa), distance converter (meter to KM, miles to KM and vice versa) ,
time converter (hours to minutes, seconds and vice versa) using packages.
3. Develop a java application with Employee class with Emp_name, Emp_id, Address, Mail_id,
Mobile_no as members. Inherit the classes, Programmer, Assistant Professor, Associate
Professor and Professor from employee class. Add Basic Pay (BP) as the member of all the
inherited classes with 97% of BP as DA, 10 % of BP as HRA, 12% of BP as PF, 0.1% of BP
for staff club fund. Generate pay slips for the employees with their gross and net salary.
4. Design a Java interface for ADT Stack. Implement this interface using array.
Provide necessary exception handling in both the implementations.
3
5. Write a program to perform string operations using Array List. Write functions for the
following
6. Write a Java Program to create an abstract class named Shape that contains two integers and an
empty method named print Area(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method print Area () that prints the area of the given shape.
8. Write a Java program that reads a file name from the user, displays information about whether
the file exists, whether the file is readable, or writable, the type of file and the length of the file
in bytes.
9. Write a java program that implements a multi-threaded application that has three threads. First
thread generates a random integer every 1 second and if the value is even, second thread
computes the square of the number and prints. If the value is odd, the third thread will print the
value of cube of the number.
10. Write a java program to find the maximum value from the given type of elements using a
generic function.
11. Design a calculator using event-driven programming paradigm of Java with the
following options.
a) Decimal manipulations
b) Scientific manipulations
12. Develop a mini project for any application using Java concepts.
TOTAL : 60 PERIODS
OUTCOMES
Develop and implement Java programs for simple applications that make use of classes,
packages and interfaces.
Develop and implement Java programs with arraylist, exception handling and
multithreading.
Design applications using file processing, generic programming and event handling.
4
Sl. Page
Name of the exercise
no. no.
1. Electricity Bill Calculator
Ex.No: 1
Date:
Electricity Bill Calculator
Aim:
To create a Java console application used to generate electricity bill based on connection
type (Domestic and Commercial) and consumption. Both are having different tariff slots.
Algorithm:
Step 2 Get the user informations [Name, Consumer Number, Reading’s of previous and current
month, Connection Type]
Step 3 Compute units consumed by user [Current Month Reading – Previous Month Reading]
Step 4 If a connection type is domestic goto step 6 Step 5 Else goto step 7
Step 6.1 If check i is less than or equal to 100 then compute sum = sum + 1 and goto
step 6.5
Step 6.2 Else if check i is greater than 100 and less than 200 then compute sum = sum
+ 2.5 and goto step 6.5
Step 6.3 Else if check i is greater than 200 and less than 500 then compute sum = sum
+ 4 and goto step 6.5
Step 6.4 Else compute sum = sum + 6 and goto step 6.5
Step 6.5 If i is equal to number of units consumed goto step 8 else return to same step
Step 7 Initialize i with 1 and sum as 0
Step 7.1 If check i is less than or equal to 100 then compute sum = sum + 2 and goto
step 7.5
Step 7.2 Else if check i is greater than 100 and less than 200 then compute sum = sum
+ 4.5 and goto step 7.5
Step 7.3 Else if check i is greater than 200 and less than 500 then compute sum = sum
+ 6 and goto step 7.5
Step 7.4 Else compute sum = sum + 7 and goto step 7.5
Step 7.5 If i is equal to number of units consumed goto step 8 else return to same step
Output:
Welcome to EB calculator
Domestic :
name : xyz
consumer number : 123
consumed units : 3300
amount to paid : 751
Commercial :
name : xyz
consumer number : 123
consumed units : 3300
amount to paid : 1252
3
Result:
The Java console application for electricity bill generator was developed and tested successfully
4
Ex.No: 2
Date:
Unit Converters Application using packages
Aim:
To create a Java console application that converts currency, distance, time. Converter
classes must be separated and used based on the package concept in java.
Algorithm:
Step 4.1 If option 1 selected get in DOLLER and display DOLLER * 66.89 as INR
Step 4.2 If option 2 selected get in EURO and display EURO * 80 as INR
Step 4.3 If option 3 selected get in YEN and display YEN * 0.61 as INR
Step 4.4 If option 4 selected get in INR and display INR / 66.89 as DOLLER
Step 4.5 If option 5 selected get in INR and display INR / 80 as EURO
Step 4.6 If option 6 selected get in INR and display INR / 0.61 as YEN
If option 6 selected get in INR and display INR
Step 4.7 If option 7 selected exit from currency converter choice goto step 2
Step 5 If user selects a Distance Converter then proceed to step 6 Step 6 Proceed with
prompting Distance Converter Choices
1. METER to KILOMETER
2. MILES to KILOMETER
3. KILOMETER to METER
4. KILOMETER to MILES
5. Exit and get the user choice.
Step 6.1 If option 1 selected get in METER and display METER / 1000 as
KILOMETER
Step 6.2 If option 2 selected get in MILES and display MILES * 1.60934 as
KILOMETER
5
Step 6.3 If option 3 selected get in KILOMETER and display KILOMETER * 1000 as
METER
Step 6.4 If option 4 selected get in KILOMETER and display KILOMETER / 1.60934
as MILES
Step 6.5 If option 5 selected exit from distance converter choice goto step 2
Step 7 If user selects a Time Converter then proceed to step 8 currency
Step 8 Proceed with prompting Time Converter Choices
1. HOURS to MINUTES
2. HOURS to SECONDS
3. MINUTES to HOURS
4. SECONDS to HOURS
5. Exit and get the user choice.
Step 8.1 If option 1 selected get in HOURS and display HOURS * 60 as MINUTES
Step 8.2 If option 2 selected get in HOURS and display HOURS * 3600 as SECONDS
Step 8.3 If option 3 selected get in MINUTES and display MINUTES / 60 as HOURS
Step 8.2 If option 4 selected get in SECONDS and display SECONDS / 3600 as HOURS.
Step 8.5 If option 5 selected exit from tim converter choice and goto step 2
Step 9 If user selects exit then display Thank You !!! and exit from the system
Step 10 Stop the process
Output
Converters
1. Currency
2. Distance
3. Time
4. Exit
Currency converter
1. DOLLOR to INR
2. EURO to INR
3. YEN to INR
4. INR to DOLLOR
5. INR to EURO
6. INR to YEN
7. Exit
Converters
1. Currency
2. Distance
6
3. Time
4. Exit
Enter your choice
2
Distance Converter
1. METER to KILOMETER
2. MILES to KILOMETER
3. KILOMETER to METER
4. KILOMETER to MILES
5. EXIT
Enter your choice
1
Enter in METERS
2789
2789.0 METERS is equal to 2.789 KILOMETER
Converters
1. Currency
2. Distance
3. Time
4. Exit
1. HOURS to MINUTES
2. HOURS to SECONDS
3. MINUTES to HOURS
4. SECONDS to HOURS
5. Exit
1. Define package.
2. What is the advantage of package?
3. What are the inbuilt java packages ?
4. What is meant by enumerated data type ?
5. Primitive data types and mathematical operations are defined under which package?
6. What is a Class Variable?
7. What is Singleton class?
8. What do you mean by Constructor?
9. List the three steps for creating an Object for a class?
10. What is a static variable?
Result
The java console application for converters [Currency, Distance, Time] was developed and tested
successfully.
7
Ex.No: 3
Date:
Employee Payroll System
Aim:
To create a Java console application for employee payroll process management. This
project includes Employee and they further classified as Programmer, Assistant Professor,
Associate Professor, Professor.
Algorithm:
Step 1 Start the process
Step 2 Prompt the user with converter choice 1. Programmer 2. Assistant Professor 3.
Associate Professor 4. Professor 5. Exit and get the choice.
Step 3 If user selects a Programmer then proceed to step 4
Step 4 Get the user details [Name, ID, Address, Mail ID and Mobile Number] and goto step 5
Step 5 Proceed to Programmers Payment Processing
Step 5.1 Get the basic pay of Programmer
Step 5.2 If user enters -1 assume basic pay as 30000 and goto step 15
Step 5.3 Else directly go to step 15
Step 6 If user selects Assistant Professor step 7
Step 7 Get the user details [Name, ID, Address, Mail ID and Mobile Number] and goto step 8
Step 8 Proceed to Assistant Professor Payment Processing
Step 8.1 Get the basic pay of Assistant Professor
Step 8.2 If user enters -1 assume basic pay as 25000 and goto step 15
Step 8.3 Else directly go to step 15
Step 9 If user selects Associate Professor step 10
Step 10 Get the user details [Name, ID, Address, Mail ID and Mobile Number] and goto step 11
Step 11 Proceed to Associate Professor Payment Processing
Step 11.1 Get the basic pay of Associate Professor
Step 11.2 If user enters -1 assume basic pay as 40000 and goto step 15
Step 11.3 Else directly go to step 15
Step 12 If user selects Professor step 13
Step 13 Get the user details [Name, ID, Address, Mail ID and Mobile Number] and goto step 14
Step 14 Proceed to Professor Payment Processing
Step 14.1 Get the basic pay of Professor
Step 14.2 If user enters -1 assume basic pay as 70000 and goto step 15
Step 14.3 Else directly go to step 15
Step 15 Compute Per_Day_Pay = original_basic_pay / no_of_days_in_the_current_month
Step 16 Get the number of days worked from user that include Cl, WH, FH and exclude the LOP
Step 17 Check no_days_worked <= no_of_days_in_the_current_month. Else display “Error
Message” and goto step 18
Step 18 Compute Current_Basic_Pay = Per_Day_Pay * no_days_worked
Step 19 Compute Following and Store
DA = (Current_Basic_Pay/100) * 97
HRA = (Current_Basic_Pay/100) * 12
PF = (Current_Basic_Pay/100) * 0.1
GROSS_PAY = Current_Basic_Pay + DA + HRA +
PF NET_PAY = GROSS_PAY - PF
8
Step 17 Display Payment Details [Name, ID, Address, Mail ID, Mobile Number, BASIC
PAY, DA, HRA,PF,GROSS_PAY, NET_PAY].
Output:
1. Programmer
2. Assistant Professor
3. Associate Professor
4. Professor
5. Exit
Programmer Selected
Enter Details
Name : Raja
ID: 101
Address : Madurai
Mail ID : raja@gmail.com
Mobile No :1234567890
Enter basic pay of programmer
40000
28
Programmer
Name : Raja
ID :101
Address :Madurai
MailID :raja@gmail.com
Mobile no.:1234567890
Earnings
Deductions
PF : 37 Rs
Gross Pay : 78018 Rs
NET Pay : 77981 Rs
1. Define inheritance.
2. What are the types of inheritance available ?
3. Does java support multiple inheritance ? if not, then Why?
4. How packages are defined and imported ?
5. What do you mean by Access Modifier?
6. What is protected access modifier?
7. What is the visibility of public access modifier in same package and other packages ?
8. Why is String class considered immutable?
9. What is the need for package?
10. How package differs from interface?
Result:
The java console application for employee payroll system was developed and
tested successfully.
10
Ex.No: 4
Date:
Java Application for ADT Stack using Interfaces
Aim:
To create a Java console application using interface concepts of java for abstract
data type stack. Stack operations must be controlled by exception handling techniques.
Algorithm:
Output:
Stack Display
11
22
33
44
1. What is ADT?
2. What is the need for ADT?
3. Define Stack and Queue.
4. What are feasible stack operations?
5. What is the difference between peek() and pop() operations in stack?
6. Differentiate stack and Queue.
7. List out the applications of stack.
8. Why do we prefer exception handling mechanism in stack and queue operations?
9. What is meant by priority queue ?
10. In what are the ways stack can be implemented ?
Result:
The java console application for abstract data type stack using java interface
concepts is developed and tested successfully.
12
Ex.No: 5
Date:
To create a Java console application for string list operations [Append, Insert at particular
Index, Search a string in a list, Display all the strings that begins with a character] using ArrayList
in java.
Algorithm:
Output:
String List Operations
1. Append a String
2. Insert a String at Positions
3. Search a String
4. List all strings
5. Display string’s Begins with a letter
6. Exit
1
Enter a String : Madurai
1
Enter a String : Chennai
1
Enter a String : Trichy
1
Enter a String : Coimbatore
4
List contains
0.Madurai
1.Chennai
2.Trichy
3.Coimbatore
2
Enter a String : Chennai
Enter a Position to insert : 1
Dindigul
4
List contains
0.Madurai
1.Dindigul
2.Chennai
3.Trichy
4.Coimbatore
3
Enter a string to be searched
Dindigul
Your sting Dindigul found at position 1
Result:
The java console application for string list operations was developed and
tested successfully.
14
Ex.No: 6
Date
Output:
Finding Area
1. Rectangle
2. Triangle
3. Circle
4. exit
Enter your choice : 1
Enter L ength and Breadth
67 78
Area of the rectangle :5226
15
Result:
The Java console application to find the area of different using abstract class concept in
java was developed and tested successfully.
16
Ex.No: 7
Date:
Bank Transaction System with User Exceptions
Aim:
To create a Java console application for Banking transaction system that helps the users to
do their credit and debit transactions and it rises user defined exception while encountering errors
in transaction and also it should be solved using exception handling techniques.
Algorithm:
Output:
Choice
1. Add money
2. Get Money
3. Details
4. Exit
Enter your choice
3
Customer Details…..
Customer name : Raja
Account number : 123456789
Customer Current Balance : 0
Customer Details…..
Customer name : Raja
Account number : 123456789
Customer Current Balance : 2000
Enter your choice
2
Enter the amount
500
Customer Details…..
Customer name : Raja
Account number : 123456789
Customer Current Balance : 1500
Customer Details…..
Customer name : Raja
Account number : 123456789
Customer Current Balance : 1600
Customer Details…..
Customer name : Raja
Account number : 123456789
Customer Current Balance : 1000
Result:
The java console application that uses user defined exception handling techniques
was developed and tested successfully.
20
Ex.No: 8
Date:
Java Application for File Handling
Aim:
To create a Java console application to handle the files and find the file properties
[Availability, Readable or Writeable or Both, Length of the File].
Algorithm:
Output:
Availability of File:
21
Result:
The java console application for handling files was developed and tested successfully.
22
Ex.No: 9
Date:
Java Application for Multi threading
Aim:
To create a Java console application the uses the multi threading concepts in java. The
Application has 3 threads one creates random number, one thread computes square of that number
and another one computes the cube of that number.
Algorithm:
Output:
23
Result:
The java console application for multithreading was developed and tested successfully.
24
Ex.No: 10
Date:
Java Application for Generic Max Finder
Aim:
To create a Java console application that finds the maximum in a array based on the type of
the elements using generic functions in java.
Algorithm:
Output:
25
Result:
The java console application for finding generic max of given elements was developed
and tested successfully.
26
Ex.No: 11
Date:
Calculator Application using java AWT packages
Aim:
To create a Java GUI application that mimics the basic and advanced functionalities of a
scientific calculator.
Algorithm:
Step 9 Repeat the process until user presses the close button then Stop the Process.
27
Output:
Calculator:
Basic Operations
Multiplication [36 X 2]
29
Result:
The java GUI application for calculator with basic and advanced functionalities was
developed and tested successfully