Sei sulla pagina 1di 219

LAB WORKBOOK

18CS2009R OBJECT ORIENTED PROGRAMMING

TEAM OOPS
K L UNIVERSITY | OBJECT ORIENTED PROGRAMMING – 18CS2009R
18SC2009R OBJECT ORIENTED PROGRAMMING

LABORATORY WORKBOOK

STUDENT NAME
REG. NO
YEAR
SEMESTER
SECTION
FACULTY

1
18SC2009R OBJECT ORIENTED PROGRAMMING

Table of Contents

LAB EXPERIMENT-1 ............................................................................................................................ 6


LAB EXPERIMENT-2 ........................................................................................................................... 15
LAB EXPERIMENT-3 ........................................................................................................................... 25
LAB EXPERIMENT-4 ........................................................................................................................... 40
LAB EXPERIMENT-5 ........................................................................................................................... 55
LAB EXPERIMENT-6 ........................................................................................................................... 74
LAB EXPERIMENT-7 ........................................................................................................................... 91
LAB EXPERIMENT-8 ......................................................................................................................... 114
LAB EXPERIMENT-9 ......................................................................................................................... 127
LAB EXPERIMENT-10 ....................................................................................................................... 142
LAB EXPERIMENT-11 ....................................................................................................................... 155
LAB EXPERIMENT-12 ................................................................................................................... 17059
LAB EXPERIMENT-13 ....................................................................................................................... 170
LAB EXPERIMENT-14 ....................................................................................................................... 176
LAB EXPERIMENT-15 ....................................................................................................................... 170

2
18SC2009R OBJECT ORIENTED PROGRAMMING

3
18SC2009R OBJECT ORIENTED PROGRAMMING

2019-20 ODD SEMESTER LAB CONTINUOUS EVALUATION

In-Lab
PRE- POST-LAB Viva Voce Total Faculty
Sl No Date Experiment Name
Lab(5M) LOGIC EXECUTION RESULT ANALYSIS (5M) (5M) (50M) Signature
(10M) (10M) (10M) (5M)

8
18SC2009R OBJECT ORIENTED PROGRAMMING

Pre-Lab In-Lab POST-LAB Viva Voce Total Faculty


Sl No Date Experiment Name
(5M) LOGIC EXECUTION RESULT ANALYSIS (5M) (5M) (50M) Signature
(10M) (10M) (10M) (5M)

10

11

12

13

14

15

2019-20 ODD SEMESTER LAB CONTINUOUS EVALUATION


18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-1
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
• L.O.1: To understand and apply the concept of Modularization and method
overloading in java.
• L.O 2: To understand and apply dot operator in an Object-Oriented Paradigm.
• L.O 3: To use variants of print function.
• L.O 4: To use conditional and loop statements for the computational statements.
• L.O 5: To understand difference between public, private and default access
specifiers.

1) You were given two problems by the teacher to be solved. (Use overloaded
methods)
a) There are ‘m’ students registered in the class with a capacity of ‘n’ seats. Your goal
is to find out the number of ways students can be seated assuming there is no
deficiency with the seats.
b) You are supposed to calculate the area of a polygon based on number of inputs
given by
the user. Polygon can be a square, a rectangle or a scalene triangle. [LO - 1,2]
Writing space for the Problem:(For Student’s use only)

6
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

7
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

8
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Tony is appointed as a billing administrator in a Restaurant. According to the norms


of the new government, GST and maintenance charges are to be displayed on the
bill. Restaurant also offers a discount to their loyal customers of 10% if the bill is
greater than 1000 rupees, else 5% for all other bills. Help him to calculate the total
bill while displaying all the components separately. [LO - 4]

Writing space for the Problem:(For Student’s use only)

9
18SC2009R OBJECT ORIENTED PROGRAMMING

3) A microbiologist wants to calculate the remaining amount of the bacteria after 5


minutes. Initially, there are ‘n’ number of bacteria. After her analysis on the given
bacteria, she finds the decreasing rate of bacteria to be 0.0028 per minute. She
approaches you, considering you to solve it through your java program. [LO - 4]

Writing space for the Problem:(For Student’s use only)

10
18SC2009R OBJECT ORIENTED PROGRAMMING

4) A Software is being developed by the management that displays SGPA of your


current semester. You are given the task to develop a module that calculates the
SGPA with respect to the secured grade points corresponding to given number of
credits in each subject. The credits for the courses are:
Graphics: 2, MVC: 4, COA: 3, Chemistry: 3, English: 2, Technical Skills: 1.5, Data
Structures: 4
Complete your Module by displaying the SGPA of current semester. [LO - 3]

Writing space for the Problem:(For Student’s use only)

11
18SC2009R OBJECT ORIENTED PROGRAMMING

5) You are appointed as a programmer of a newly taken up project for Bank-Customer


transactions of a National Bank. The management of the bank requires the customer
to give out their name, account number, and the initial amount present in their
account. The customer will request for the deposit and withdraw of amount from
their account. Your program should be able to check whether the request can be
accepted depending on the account balance in their account and display the
appropriate message for their transaction while also displaying the remaining
balance in his/her account. Make sure your program ensures the access of account
number only to the account holder and the bank (Use two different classes for
deposit and withdrawal). [LO - 1,3]

Writing space for the Problem:(For Student’s use only)

12
18SC2009R OBJECT ORIENTED PROGRAMMING

6) An IT Industry recruited a few employees and wants to maintain a record of their


details containing their name, age and salary. You have been given the task to write
a program to display the details, mentioning the salary to be hidden to others except
that employee and the management. [LO - 5]

Writing space for the Problem:(For Student’s use only)

13
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

14
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-2
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To understand and apply concept of arrays.
L.O.2: To use command line arguments as user inputs
L.O.3: To understand java API and be able to use Math class and its static methods
L.O.4: To be able to differentiate pass by value and pass by reference
1) Ramesh’s house is located at a junction from which the places of his four friends are
located at two coordinate points each. He must be at either one of their houses at
the same time. Help him choose which house to go to by finding out the one with
the nearest distance from his place. The coordinates of their houses are as follows:
[LO:1,3]

Name Coordinates
Ramesh (3,2)
Friend A (2,3)
Friend B (0,0)
Friend C (5,8)
Friend D (1,4)

Writing space for the Problem:(For Student’s use only)

15
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

16
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Pavan and Praveen are playing rock - paper - scissor. Here rock = 0, paper = 1, scissor
= 2. Their throws are as follows: [LO:1,3]

Rounds Round Round Round Round Round Round Round Round Round Round
1 2 3 4 5 6 7 8 9 10
Pavan 0 1 1 2 0 0 1 2 1 0
Praveen 1 2 0 1 0 2 0 1 1 2
Compare and print the score of each of the player at the end of ten rounds and
declare the winner.
Writing space for the Problem:(For Student’s use only)

17
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

18
18SC2009R OBJECT ORIENTED PROGRAMMING

3) The Government adopts the orphans of various age groups and sends them to an
orphanage. Since the warden doesn’t know the exact count of the orphans help him
by writing a program to count the total number of orphans and find the frequency of
similar age groups. (Use command line arguments as user input). [LO:1,2]
Writing space for the Problem:(For Student’s use only)

19
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

20
18SC2009R OBJECT ORIENTED PROGRAMMING

4) Captain Jack Sparrow went for a treasure hunt with his crew. He came to an Island
and found five caves in a series numbered as (2, 5, 7, 4, 9). Help Captain Sparrow to
(1) Find the caves with treasure?
Hint: -G = (cave number+3) ^2 %10
If (G < 5) -> Cave has treasure.
(2) Find the caves with a new Treasure Map?
Hint: -M = |10 - cave number|%3
If (M==0) ->Cave has treasure map. [LO:1,3]
Writing space for the Problem:(For Student’s use only)

21
18SC2009R OBJECT ORIENTED PROGRAMMING

5) Tom and Jerry found two bags of apples. The bag that Jerry chose contains 5 apples and
the bag chosen by Tom has 3 apples. Tom wants to have more apples, so he swaps the bags.
Write a program to display the apples in the two bags before and after swapping. [LO:4]
Hint:-(Try using call by value and call by reference; Write which can be used to swap)
Writing space for the Problem:(For Student’s use only)

22
18SC2009R OBJECT ORIENTED PROGRAMMING

6) A Person had gone on a holiday. He decided to use his savings amount of 500$. He
allotted certain amount of money as his budget. During the holiday, he first goes on a safari
ride which costs him about $30. Then he goes out for lunch which costs him about $40.
Later, he finishes the day off by going for a movie which costs him $15. Help him find out
the amount left by the end of the holiday. [L.O:3,4]
(Every activity is a method in the class. Only initializing amount is called by value)
Writing space for the Problem:(For Student’s use only)

23
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Write a program to help Alex find out the date and time. [LO:4]
Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

24
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-3
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To understand and apply instantiation of a class
L.O.2: To use dot(.) operator to invoke members and methods of an instance
L.O.3: To be able to differentiate scope of variable w.r.t to static and instance methods
L.O.4: To be able to create objects of various classes from java API packages like javax.swing,
java.io
L.O.5: To implement inner classes in java.

1) Rakesh is participating in a Hackathon and it requires him to make a Login page. Help
him out by writing a program to create the page. It should look as follows: [L.O 4]

Writing space for the Problem:(For Student’s use only)

25
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

26
18SC2009R OBJECT ORIENTED PROGRAMMING

2) A Mathematics faculty in class started asking questions about finding out the square
root of a given number. He now put up a challenge to Satya to tell all the numbers
starting from 1 to the given number (say n). Write a program to help him find out the
square root of all those numbers: [ L.O 1]
Writing space for the Problem:(For Student’s use only)

27
18SC2009R OBJECT ORIENTED PROGRAMMING

3) You have a file which contains confidential data in it. You want to send that data to
one of your executives, but you need to send a duplicate copy. Copy the data from
original file to duplicate file and send it: [ L.O 4]
Writing space for the Problem:(For Student’s use only)

28
18SC2009R OBJECT ORIENTED PROGRAMMING

4) While on his duty, a traffic police had the task of checking the speed of vehicles. It is
given that if the speed is above 90kmph, there should be a fine of 1000/- imposed on
the vehicle. Help him out by creating a program to for imposing of the fine. (Create
two classes for police and speedcheck. All methods must be static): [ L.O 2,3]
Writing space for the Problem:(For Student’s use only)

29
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

30
18SC2009R OBJECT ORIENTED PROGRAMMING

5) Full moon occurs for every 29.52 days. The last full moon occurred on August
14th,2019. Calculate next two full moon days without creating object of the class and
calculate two previous full moon days by creating object of the class: [ L.O 3]
Writing space for the Problem:(For Student’s use only)

31
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

32
18SC2009R OBJECT ORIENTED PROGRAMMING

6) Alex was asked to predict number of characters, words and lines in a file. He was just
given the file name. Help Alex to predict, by passing file name as command line
argument: [ L.O 4]

Writing space for the Problem:(For Student’s use only)

33
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only

34
18SC2009R OBJECT ORIENTED PROGRAMMING

7) You are working in DELL company. You’ve been asked to develop a program for the
service center website of the company. It should contain Purchasing and Servicing
options (Consider them as classes). Purchase class contains purchaseInspiron and
purchaseAlienware methods, Service class contains serviceOfLaptop and serviceOfPc
methods. Both service and purchase classes are in class Dell. (Use Inner Classes):
[L.O 5]
Writing space for the Problem:(For Student’s use only)

35
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

36
18SC2009R OBJECT ORIENTED PROGRAMMING

8) University is accepting new admissions for the upcoming academic year. In order to
be accepted into the university, the student needs to submit their JEE mains scores.
If their total is greater than 80%, they can get into the university else they can’t get
an admission. [L.O 5]

Complete the given program:

class Result

public void displayResult ()

//Fill this line

double tm=sd. TotalMarks ();

if((tm/360) *100 >= 80)

System.out.println("Eligible for the admission in college");

else

System.out.println("Ineligible for admission");

public class StudentDetails

double Maths=100, Physics=100, Chemistry=100;

37
18SC2009R OBJECT ORIENTED PROGRAMMING

void setMarks (double Maths, double Physics, double Chemistry)

// Fill these lines

double TotalMarks ()

//Fill this line

return totalMarks;

class InnerClass

public static void main (String [] args)

38
18SC2009R OBJECT ORIENTED PROGRAMMING

Result.StudentDetails rsd=new Result (). new StudentDetails ();

rsd. setMarks (108,89,98);

//FILL THIS LINE//

r. displayResult ();

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

39
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-4
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To understand constructors and apply the concept to instantiate a class through
overloaded constructors.
L.O.2: To understand the usage of public and private constructors.
L.O.3: To apply the concept of encapsulation through mutators and accessors.
L.O.4: Apply the object-oriented concepts studied till now to develop a test-based menu
driven standalone software system to a real-world problem. (Perform Unit Testing)
L.O.5: Apply the concept of Aggregation vs Composition.
1) A lottery shop owner is running two deals for his customers. In the first deal, he gives
out one token at a cost of 5/- and in the second deal he gives out two tokens at a
cost of 10/-. Each token value ranges from 0 to 5. Each customer gets one chance of
playing the game of BIG SIX WHEEL. If he gets a value which is less than or equal to
the token value, he wins a prize. Help him out by writing a program for this. (Use
constructor overloading) [ L.O 1]
Writing space for the Problem:(For Student’s use only)

40
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

41
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

42
18SC2009R OBJECT ORIENTED PROGRAMMING

2) A customer of a bank wants to withdraw/deposit money from his account. There are
3 ATMs in his town. Help him out by writing a program such that his balance will be
updated after a transaction in any of the ATMs. (Use ‘Account’ as Singleton Class and
it should be Early Instantiated) [L.O 2]
Writing space for the Problem:(For Student’s use only)

43
18SC2009R OBJECT ORIENTED PROGRAMMING

3) A Netcenter has one printer and four systems which has a total of 100 papers. Write
a program such that after every print command the number of papers left should be
displayed on every system. Use GUI, consider each frame as a system. (Use Singleton
class) [L.O 2]
Writing space for the Problem:(For Student’s use only)

44
18SC2009R OBJECT ORIENTED PROGRAMMING

4) You’re an agent of the R.A.W agency who needs to take in the details of the agents
and store them in the database. All the instance variables must be private. Write a
program to access and update the details whenever necessary and display them in
the following format:
Name: Bond
Age: 42
ID: 007
Location allocated: Britain (Use mutators and accessors) [L.O 3]
Writing space for the Problem:(For Student’s use only)

45
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

5) MATCH THE FOLLOWING


(Assume ‘A’ is the class name)
public [ ] a) Parameterized Constructor
private [ ] b) No-argument constructor
A (4,5){ } [ ] c) have only one object
Singleton class [ ] d) accessible anywhere
A (){ } [ ] e) accessible within the class only
Accessors [ ] f) only accessible in class and its subclass
Mutators [ ] g) Methods to access instance variables
h) Methods to initiate instance variables

46
18SC2009R OBJECT ORIENTED PROGRAMMING

6) A Restaurant serves dishes of three types: Veg, Non-Veg and Egg represented by
green, red and brown color codes respectively. Help them out by writing a menu driven
program to display the various dishes depending on the type of food the customer opts
for. [L.O 4]
Writing space for the Problem:(For Student’s use only)

47
18SC2009R OBJECT ORIENTED PROGRAMMING

7) A company wants to digitalize their manual records of the employee details


(Employee ID, Employee name, Employee Department). If all the three fields are given,
use the given details. If not, use the default values.
(Use Constructor Overloading) [L.O 1]
Default values are:
ID: 0
Name: #
Department: #
Writing space for the Problem:(For Student’s use only)

48
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

49
18SC2009R OBJECT ORIENTED PROGRAMMING

8) You need to write a program for a government website which maintains the census
details of the nation. You need to consider Total, male and female population as the
attributes. It should be updated after every census. All the attributes should be private.
(Use accessors and mutators to update and retrieve data.) [L.O 3]
Writing space for the Problem:(For Student’s use only)

50
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

51
18SC2009R OBJECT ORIENTED PROGRAMMING

9) You are working as a Data entry operator in a Sports academy which teaches cricket
and football to young kids. As the new calendar year starts a new batch of kids join the
academy and you need to store their details. All of them have instance variables as their
name, their age and their country in the class player. Depending on the sport the other
variables vary, like the class cricketer has matches, runs, wickets, class footballer
contains matches and goals. Using these criteria print the data of a cricketer and a
footballer using aggregation and composition. [L.O.5]
Writing space for the Problem:(For Student’s use only)

52
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

53
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

54
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-5
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To Apply the concept of Inheritance using Java.
L.O.2: To understand and use Dynamic Polymorphism.
L.O.3: To use the keyword “Super” as a reference and as a constructor.
L.O.4: To understand and use “Protected” access specifier.
L.O.5: To use Single Responsibility Principle, Open Closed Principle and Liskov Substitution
Principle.
L.O.6: To use abstract classes for solving real world problems.
L.O.7: To understand and apply template method and null object design pattern

1) Patrick found out that his distant relative had passed away recently and that he had
inherited one of his property papers which contains text. He has an interest in
sentences being PANGRAMS and this text wasn’t in that format. He found that he
had a choice of buying the missing letters from the local store to complete it as
PANGRAM. Each letter has its own price and you need to write a program to help
him find out the cheapest way to make it into a PANGRAM. (Use Inheritance) [L.O.1]

Writing space for the Problem:(For Student’s use only)

55
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

56
18SC2009R OBJECT ORIENTED PROGRAMMING

2) A customer walks into a KFC outlet and sees that he has two options: veg and non-
veg. He observes that plain veg burger costs 80/- and plain non-veg burger costs
120/- each. But he wishes to have extra mayonnaise and either of extra
veggies/chicken on each of his burgers. Help the outlet by writing a program which’ll
help them calculate the cost of the basic burger and also include the cost of the
condiments if he chooses to add any. (Use Inheritance and Null Object Design
Pattern) [L.O.6,7]

Item Cost
Mayonnaise 30/-
Veggies 45/-
Chicken 60/-
Writing space for the Problem:(For Student’s use only)

57
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

58
18SC2009R OBJECT ORIENTED PROGRAMMING

3) Your local library needs your help related to library management and wants you to
develop a program that will help them to calculate the fine .Remember that the
name and the number of days the borrower had the book with them should be
protected and display the information using inheritance concept .After 15 days fine
will be charged as 2 rupees per day until the day of submission, if there is no charge
simply print “NO FINE” else print the fine.[L.O.4]

Writing space for the Problem:(For Student’s use only)

59
18SC2009R OBJECT ORIENTED PROGRAMMING

4) Abhinav has given his credit card to his three sons for their monthly expenses. After
the turn of the month, he gets a bill of 1,00,000/- Rohit tells him that he had used
15,000/- in that month. Srikanth and Kalyan tell him that they’ve used 35,000/- and
50,000/- respectively. Help Abhinav to find out percentage of amount each of his
sons used in that month. Consider creditBill as abstract class containing a return
method and an abstract method. Use Dynamic Polymorphism. [L.O.2,5]

Writing space for the Problem:(For Student’s use only)

60
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

61
18SC2009R OBJECT ORIENTED PROGRAMMING

5) Kartish is the head of the village panchayat and decides to collect the data related to
the population, total income and the average income of the village and stores it in a
class which is in a package village. Help him out to create another package and
access the village information. (Use Protected access specifier) [L.O.4]

Writing space for the Problem:(For Student’s use only)

62
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

63
18SC2009R OBJECT ORIENTED PROGRAMMING

6) Ramesh owns a company and ran it for a period of 7 years with a profit of 80cr per
annum. He falls sick and his son Suresh inherits the ownership of the company and
runs it for a period of 6 years with a profit margin of 120cr per annum. Complete the
given code. (Use the keyword ‘Super’) [L.O.3]
class Ramesh
{
Ramesh (int yearsWorked, int profitPerAnnum)
{ //Fill the code

}
}

class Suresh extends Ramesh


{
Suresh (int yearsWorked, int profitPerAnnum)
{
//Fill the code

}
}

class Company

64
18SC2009R OBJECT ORIENTED PROGRAMMING

{
public static void main (String [] args)
{
//Fill the line

}
}

OUTPUT FORMAT:
Ramesh worked for 7 years and earned profit 80 crores
Total Profit earned by Ramesh is: 560
After Ramesh's ill health his son Suresh, took over to develop his father’s company
Suresh worked for 6 years and earned profit 120 crores
Total Profit earned by Suresh is: 720

65
18SC2009R OBJECT ORIENTED PROGRAMMING

7) A student was asked by his teacher to solve a problem which states that he should
be finding out the area of a rectangle by writing a program for it. After writing the
code, he was then asked to find out the area of any given polygon without modifying
the already written code only by extending it. Help him out by writing a program for
it. [L.O.5]
Writing space for the Problem:(For Student’s use only)

66
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

67
18SC2009R OBJECT ORIENTED PROGRAMMING

8) Mobile phone evolution initially happened in 4 phases. It started with phones having
only call feature, then it extended to phones to having messaging also. In the next
generation phones also had camera and in the final generation of that revolution
they started having internet also. Write a program to print all the features present in
a 4th generation phone. (Use inheritance) [L.O.1]

Writing space for the Problem:(For Student’s use only)

68
18SC2009R OBJECT ORIENTED PROGRAMMING

9) You are the manager of a textile showroom. According to seasons and festivals you
have to apply coupons so to attract the customers. You have two coupons available
with you i.e. “RAMZAN” and “CHRISTMAS” which gives different discounts for
different coupons. You have to add one more coupon “DIWALI” to your program
without modifying the code by just extending it. [L.O.5]

Writing space for the Problem:(For Student’s use only)

69
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

70
18SC2009R OBJECT ORIENTED PROGRAMMING

10) Admissions for your college have begun and you are required to develop a program
which checks the eligibility criteria for the freshers. If a male student gets less than
2000 rank in EAMCET, he is eligible for admission and has a fee of 100000/- and if a
female student gets less than 1600 rank in EAMCET, she is eligible for admission and
has a fee of 90000/-. Any student wanting to avail the hostel facility has to pay an
additional fee of 100000/- (Use Template Design Pattern) [L.O.7]

Writing space for the Problem:(For Student’s use only)

71
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

72
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

73
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-6
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To understand the concept of Generic Class and apply to real world problems.
L.O.2: To apply the keywords try & catch to handle exceptions.
L.O.3: To use and implement the concepts of Inheritance and Abstract class.
L.O.4: To understand and apply Observer Design Pattern.
1. Rohit gives a task to his younger brother where he will be given three variables
which may hold any type of data. The task here is to print the given inputs in the
same format. [HINT: Use the concept of generic methods.] [L.O 1]
18 10861 Virat
Sachin 10 18426
7 Dhoni 10534
10201 333 Gayle
ABD 9577 17

Writing space for the Problem:(For Student’s use only)

74
18SC2009R OBJECT ORIENTED PROGRAMMING

2. An old man wants to distribute sweets to children near his home. He was confused
of how many sweets he must give to each child. Help the old man by writing a
program where the number of sweets and number of children are initialized using
parameterized constructor. Observe what happens when there are zero number of
children and handle the exception if any. [ L.O 2]

Writing space for the Problem:(For Student’s use only)

75
18SC2009R OBJECT ORIENTED PROGRAMMING

3. Profit or Loss in Stock market is decided by the following formula:


(x^3+x^2+x) / ((f^3+g^3+h^3) - x)
where x is the value of a single share and
f = x% 10, g = (x/100), h = (x%100)/10
The values of x for various companies are as follows

153 505 370 307 480 407 600 371 999


Using the steps of exception handling (try, catch) find whether the companies are
getting a profit or loss and print the exception if there is any. Think and draw
conclusion a on why there arises an exception for certain inputs. [ L.O 2]
Writing space for the Problem:(For Student’s use only)

76
18SC2009R OBJECT ORIENTED PROGRAMMING

4. Analyse and guess the output of the following code. [L.O 2]


class Exc
{
public static String lem ()
{
System.out.println("lem");
return "return from lem";
}
public static String foo ()
{
int x = 0;
int y = 5;
try
{
System.out.println("start try");
int b = y / x;
System. out. println ("end try");
}
catch (Exception ex)
{
System. out. println ("catch");
lem ();
}
return "oo";
}

public static void bar ()


{
System. out. println ("start bar");
String v = foo ();
System.out.println(v);
System.out.println("end bar");
}
public static void main (String [] args)
{
bar ();
System.out.println("End\n");
}
}

77
18SC2009R OBJECT ORIENTED PROGRAMMING

5) Election committee wants to check whether the voter is eligible to vote or not. The
person can vote if his age is greater than 18. Help the Election committee by developing a
code which arises exception if the voter age is less than 18 then print the exception and
“VOTER IS NOT ELIGIBLE TO VOTE”, otherwise print “VOTER IS ELIGIBLE TO VOTE”. [L.O 2]
Writing space for the Problem:(For Student’s use only)

78
18SC2009R OBJECT ORIENTED PROGRAMMING

6) A student was asked by his faculty to print the name of Sachin Tendulkar, his total
number of runs scored in ODI’s and his average in one line and to print them in reverse
order in the next line. Create an object and pass the data to the constructor Statistics. Help
him out by writing out a code. [L.O 1]
Writing space for the Problem:(For Student’s use only)

79
18SC2009R OBJECT ORIENTED PROGRAMMING

7) There’s a Christmas eve and so every shopping mall in the city conducted many spot
events and games. In a lucky draw, they decided to gift every customer who had their
‘names’ special. “Special”, they meant: The String ‘name’ with length ‘N’, should have 2
or more than 2 special sets. “Special sets” differ from 1 mall to the other.
• Special set for mall 1 meant: the index ‘i’ (1≤i≤N) such that i th character of the name
is vowel and the (i+1) th letter is a consonant.
• Special set for mall 2 meant: the index ‘i’ (1≤i≤N) such that i th character of the name
is vowel and the (i+2) th letter is a consonant.
Considering “name” and “shopping mall” as inputs, check whether you could
win the lucky draw or not, while also display the required message. Hint: Take ‘Mall’
as an abstract class and ‘special set’ as an abstract method in it. Override the
method to the subclass’s mall 1, mall 2. [L.O 3]

Writing space for the Problem:(For Student’s use only)

80
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

81
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

82
18SC2009R OBJECT ORIENTED PROGRAMMING

8) One of your friends John has come over from the States and is curious to know about IPL.
Explain him about the working of the league by printing the points table of IPL 2018. Points
table is as follows:

Team Matches Won Lost No Total NRR


played Result Points
KXIP 14
SRH 14
CSK 14
MI 14
KKR 14
RCB 14
DC 14
RR 14
Use the concept of generic method and complete the table. [L.O 1]

Writing space for the Problem:(For Student’s use only)

83
18SC2009R OBJECT ORIENTED PROGRAMMING

9) There’s an online pizza order store which accepts orders for Veg-Pizza and Non-veg Pizza
each in different sizes and types. Size of Pizza are: (6,9,12 inches); Types of Pizza are: (PLAIN,
DELUXE, SUPREME).
The cost of Pizza are as follows:

• For Veg-Pizza the base price is Rs.50 multiplied by the size of pizza for PLAIN type
and extra charges are added for premium types. (DELUXE Rs.100 extra charge and
SUPREME Rs.150 extra charge)
• For NonVeg-Pizza the base price is Rs.100 multiplied by the size of pizza for PLAIN
type and extra charges are added for premium types. (DELUXE Rs.150 extra charge
and SUPREME Rs.200 extra charge)
They also wanted to calculate total sales made. There is a total of 5 classes; one
abstract class Pizza, Classes VegPizza and NonVegPizza, user defined exception class –
InvalidPizzaException and Main class PizzaOnline.

The classes have following properties:

Pizza
It is an abstract class and has following methods:

• abstract float calculatePrice()


• abstract pizzatype(int size, String type)
• Public Boolean validate(int size, String type) – This method returns true if the valid
size and type are given else returns false.

VegPizza
This extends Pizza and has private members size and type. (variables)

• pizzatype (int size, String type) – this method validates the size and type of pizza by
using validate method from Pizza, if the result is false it then throws
InvalidPizzaException.
Else assigns the values to instance variables size and type.
• Float calculatePrice () – Calculates the price of Pizza for the given size and type using
the above prices.

84
18SC2009R OBJECT ORIENTED PROGRAMMING

NonVegPizza
This extends Pizza and has private members size and type. (variables)

• pizzaType (int size, String type) – this method validates the size and type of pizza by
using validate method from Pizza, if the result is false it then throws
InvalidPizzaException.
Else assigns the values to instance variables size and type.
• float calculatePrice () – Calculates the price of Pizza for the given size and type using
the above prices.

PizzaOnline
This is the class which contains main method, contains a private float variable totalSales.
Contains the following methods:

• float order (Pizza pizza) – calculates price of pizza


Finally, print the cost of the meal. [L.O.3]

Writing space for the Problem:(For Student’s use only)

85
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

86
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

87
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

88
18SC2009R OBJECT ORIENTED PROGRAMMING

10) You are working in a bank in the foreign currency department and are asked by your
superiors to develop a program which takes in the value of rupee as dynamic input and
converts it into dollars and euros. It is known that 1 dollar = 69.79 rupees and 1 euro = 78.40
rupees (Use Observer Design Pattern) [L.O.4]

Writing space for the Problem:(For Student’s use only)

89
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

90
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-7
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: Apply the concept of Interfaces.
L.O.2: Understand and use Multiple Inheritance through Interfaces.
L.O.3: Understand and apply “Factory Method”, “Decorator”, “Chain of Responsibility”,
“Adapter” and “Command” design patterns to real-world applications.
L.O.4: Apply the concept of Facade Class
L.O.5: To use Interface Segregation Principle.
L.O.6: Implement Event-driven programming with the help of Interfaces.
L.O.7: To use Object Composition.
1) You are a journalist and are required to submit a report on the number of
accidents that had occurred in your area. Collect the information of accidents caused
by car, bus and bike from your local NGO’s and write a program that will print the
number of accidents of each type that had occurred. (Use Interface and it contains a
method numberOfAccidents, also use Adapter Design Pattern.) [L.O.1,3]

Writing space for the Problem:(For Student’s use only)

91
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

92
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Mark owns a Xerox shop. He uses a Smart Printer which can Print, Fax and Scan to
render his services to the customers. As the business is booming, he bought and
installed an Economic Printer which can only print. Implement interfaces for both
printers using Interface Segregation Principle. [L.O.5]

Writing space for the Problem:(For Student’s use only)

93
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

94
18SC2009R OBJECT ORIENTED PROGRAMMING

3) Dominos wanted to add a pizza customization feature in their app so that the
customer can have the liberty to choose the base and customize the toppings.
Implement the program using decorator design pattern and print the price of the
pizza based on the customized toppings. [L.O.3]

Writing space for the Problem:(For Student’s use only)

95
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

96
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

97
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

98
18SC2009R OBJECT ORIENTED PROGRAMMING

4) A bank manager wants to improve the rate of customers using the bank. He
arranged a meeting with a software company to discuss the ways to improve the
customers. You pointed out that the bank interface needs to be more user-friendly
to attract more customers. Use the facade design pattern to implement a program
which contains all the daily transactions like withdraw, deposit and transfer amount.
[L.O.4]

Writing space for the Problem:(For Student’s use only)

99
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

100
18SC2009R OBJECT ORIENTED PROGRAMMING

5) The vice-chancellor of KL University came to know that there was a problem for
visitors on identifying the location of the department blocks and their timings. In
order to resolve this issue, you are assigned to design a software that displays the
name of the block for the respective department, timings as well as the HOD of the
department. Implement factory method design pattern to resolve this issue. [L.O.3]

Writing space for the Problem:(For Student’s use only)

101
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

102
18SC2009R OBJECT ORIENTED PROGRAMMING

6) A travel agency has many buses which travel long distances. They need their buses
to have a full tank before every journey starts. You are required to develop a
program which will calculate the amount of fuel required to reach the destination
and the average speed that the driver should maintain to reach the destination on
time(Hint: interface one should contain abstract method avgspeed and distance that
driver should travel, interface 2 contains time and abstract method fuel, take static
inputs) [L.O.2]

Writing space for the Problem:(For Student’s use only)

103
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Samsung had taken a patent for certain attributes (shape, thickness, weight) and
you are part of Apple and are required to know about the details that they’ve
patented. So, write a java program to retrieve the data. Your program must consist
of two classes in which Samsung class is “final”. The “final” class contains the
attributes of mobile. By using composition in Apple class, retrieve the data from
“final” class and display it to your stakeholders. [L.O.7]

Writing space for the Problem:(For Student’s use only)

104
18SC2009R OBJECT ORIENTED PROGRAMMING

8) A car manufacturer wants to manufacture cars as per the customer’s choice of


color and the other materials were predefined by the company. You are the engineer
hired by the car manufacturer to help them out in manufacturing cars in accordance
with customer’s choice of colors. (Use Interface) [L.O.1]

Writing space for the Problem:(For Student’s use only)

105
18SC2009R OBJECT ORIENTED PROGRAMMING

9) Your friend wanted to know about the Christopher Nolan’s Batman Trilogy, and he
has asked you to give brief details about it. You decide to make an event driven
program consisting of classes batmanBegins, theDarkKnight and theDarkKnightRises.
Each class consists of information about the cast, release date and budget.
Implement those classes by using the interface movieInfo. Create one button for
each class such that the information is displayed when it is selected. [L.O.6]

Writing space for the Problem:(For Student’s use only)

106
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

107
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

108
18SC2009R OBJECT ORIENTED PROGRAMMING

10) A student was asked by his faculty to take in two operands and one operator as
inputs and perform the necessary operation using Chain of Responsibility design
pattern. (Do not use switch case or if-else statements) [L.O.3]

Writing space for the Problem:(For Student’s use only)

109
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

110
18SC2009R OBJECT ORIENTED PROGRAMMING

11) You are required to perform three operations on a file: Open, close and write. On
execution of each operation the system should print that the particular operation
has been successful. Use command design pattern to implement the above problem.
[L.O.3]

Note: Implement it using Interface.

Writing space for the Problem:(For Student’s use only)

111
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only

112
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

113
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-8
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To understand and apply Serializable.
L.O.2: To understand and apply Comparable.
L.O.3: To understand and apply Cloneable.
L.O.4: To use Vectors and Lists.
L.O.5: Understand and apply State Design Pattern

1) You are working in Swiggy and you are required to write a program which takes in the
customer’s order and address and then gives the restaurant, your order details. The
delivery executive will be given both the order details and address details. Clone and
print the information sent to the delivery executive and the information sent to the
restaurant separately. [L.O.3]

Writing space for the Problem:(For Student’s use only)

114
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

115
18SC2009R OBJECT ORIENTED PROGRAMMING

2) The Vijayawada Traffic Police has asked you to develop a program which takes in the car
number, name and the fine and stores it in a vector. Then compare the fine and sort
them in ascending order and print them. (Use comparable interface) [L.O.2]
Writing space for the Problem:(For Student’s use only)

116
18SC2009R OBJECT ORIENTED PROGRAMMING

3) As an assignment, you were asked by your faculty to develop a program which takes in
the ID number and name as inputs and converts them into a byte stream and store that
into a file. (Use Serializable) [L.O.1]
Writing space for the Problem:(For Student’s use only)

117
18SC2009R OBJECT ORIENTED PROGRAMMING

4) The Section IV Students of K L university want to save the details of students present in
their class which include student ID number and student name. Help them by creating a
java program using vectors. Your program should contain methods to add new students,
display students, find students, remove students. (hint: use 2 vectors v1 to save name,
v2 to save ID.no, the S.no of student will be the index of vector) [L.O.4]

Writing space for the Problem:(For Student’s use only)

118
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

119
18SC2009R OBJECT ORIENTED PROGRAMMING

5) A student was asked by his faculty to take in two lists as inputs and compare and sort
them. As the output he should be printing the common elements in both the lists in the
first line. He should then print the elements that are present in the first list but not in
the second list in a new line and then print the elements present in second list but not in
the first one is another line. [L.O.2,4]

Writing space for the Problem:(For Student’s use only)

120
18SC2009R OBJECT ORIENTED PROGRAMMING

6) A worker is assigned with a work by the Management and there are few required
components to get the work done by the worker. He makes the list of the components
required and clone them while also forwarding a copy to the management. The
management would then remove the available components from the cloned list and
then would forward the unavailable list to the owner for requirement. Help the
management to display the cloned list along with hash code and the list of the
components that are sent to the owner. [L.O.3,4]

Writing space for the Problem:(For Student’s use only)

121
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Your mother works as a teacher for a Secondary School. At the end of the academic
year, she needs to finalize the ranks of the students according to the total marks
obtained by students. Help her in doing this by using comparable Interface. She would
be giving you the LIST which consists of details of the student consisting Name, ID, Total
marks of the Student. [L.O.2,4]
Writing space for the Problem:(For Student’s use only)

122
18SC2009R OBJECT ORIENTED PROGRAMMING

8) A student wants to increase his laptop performance by increasing the ram size by
adding an additional 8 Gb RAM. He wants to buy it at an optimal cost, so he visited
different online stores and collected ram details (price, brand, store, product id) from
different stores. Help him by writing a java program that stores the data in an arraylist
and sort in ascending order of price using java Comparable interface. [L.O.2,4]

Writing space for the Problem:(For Student’s use only)

123
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

124
18SC2009R OBJECT ORIENTED PROGRAMMING

9) Your friend wants to have a security system for his room which depends on Floor
sensitivity, Temperature sensitivity and Sound sensitivity. These factors should be
activated when he exits the room and the door should remain locked, whereas the door
should unlock, and the factors should be deactivated when he enters the room. Develop
a program to help him out. (All the required methods should be defined in an interface
and implement using State Design Pattern) [L.O.5]

Writing space for the Problem:(For Student’s use only)

125
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

126
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-9
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: Implement multithreading using runnable interface.
L.O.2: Compare Implementation of multithreading using runnable interfaces with extending
a thread class
L.O.3: Understand and apply thread synchronization with appropriate keywords and apply
the same to real world problems.
1) You are given a task of printing the first five natural numbers assigned to all three
different threads which should be created by implementing runnable interface. Run
this program for three times and check the printing style each time. [L.O.1]

Writing space for the Problem:(For Student’s use only)

127
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

128
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

129
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Rohan was asked by his teacher to develop a program which takes in a dynamic user
input and prints all the prime numbers till that number and then prints all the
composite numbers till that number. Help him out by developing the program to do
so. Use one thread each for both prime and composite numbers and apply the
concept of thread synchronization [L.O.3]

Writing space for the Problem:(For Student’s use only)

130
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

131
18SC2009R OBJECT ORIENTED PROGRAMMING

3) You are editing your friend’s short film which is made up of 15 frames. You need to
develop a program which makes sure that the audio and video are running parallelly.
Use one thread each for audio and video. Make sure both the threads have equal
sleep time. Use runnable interface to implement the threads. [L.O.1]

Writing space for the Problem:(For Student’s use only)

132
18SC2009R OBJECT ORIENTED PROGRAMMING

4) Tony was asked to develop a program which takes in five alphabets as dynamic user
input and stores them in an array. He passes the array to two threads. First one
should traverse the array, and the vowels present in it should be printed and the
second thread should print the consonants present in the array. Help him out by
writing the program. [L.O.1]

Writing space for the Problem:(For Student’s use only)

133
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

134
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

135
18SC2009R OBJECT ORIENTED PROGRAMMING

5) You are asked to take two integer values as dynamic user inputs. The values are then
passed to two threads where their respective multiplication table’s logic (up to 10)
should be written in a synchronized block and print them. [L.O.3]
Writing space for the Problem:(For Student’s use only)

136
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

137
18SC2009R OBJECT ORIENTED PROGRAMMING

6) You are asked to take two threads which print the statement “hello world from
thread ______ (thread name)” five times where it should be written in a
synchronized method. Develop a program to do so. [L.O.3]

Writing space for the Problem:(For Student’s use only)

138
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Ram is working in Indigo Airlines and has been asked by his superiors to develop a
program which helps train the newly recruited air flight attendants by taking in their
name, designation and the flight starting point and destination to which they’re
allotted. It should then print the information in the following format:
Welcome on board to Indigo Airlines
Good morning (Time of the day)!
This is your _____ (Designation), _____ (Name) speaking!
Thank you for choosing Indigo Airlines to travel from ____ (Starting point) to _____
(Destination)
Wish you have a safe and comfortable journey.
(Implement the threads using runnable interface by extending a thread class) [L.O.2]

Writing space for the Problem:(For Student’s use only)

139
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

140
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

141
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-10
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To be able to use Treeset for real-world applications required for unique ordered
data.
L.O.2: To be able to use Hashset for real-world applications required for unique ordered
data.
L.O.3: To use Comparable Interface on a Set Data Structure.

1. Akash was asked by his faculty to take in ten integer values as dynamic user inputs and
store them in a treeset. He was then asked to print the minimum and maximum value
from the given values and also find the sum of the given values (Use iterator). He was
also asked to take another integer as input and check whether it is present in the treeset
or not. Help him out by writing a program for the above statement. [L.O.1]
Writing space for the Problem:(For Student’s use only)

142
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

143
18SC2009R OBJECT ORIENTED PROGRAMMING

2. You are part of an agency which helps the Government in collecting the census data and
are required to write a program which verifies the names of the users from a certain
street. The program should take in the number of names to be entered and the names
of the citizens in that street. It should also enable you to search for a citizen’s name and
print yes if the name is present and no if it is not. Store the names in a Treeset. [L.O.1]
Writing space for the Problem:(For Student’s use only)

144
18SC2009R OBJECT ORIENTED PROGRAMMING

3. Ram is working as a Data entry operator in KLEF and wants you to develop a program
which helps him digitalize the process of entering data into registers. Your program
should be able to add records of students into the register, retrieve the records
whenever needed and remove a student’s record when needed. It should also be able to
clear the entire register when needed. Store them in a Treeset and use Singleton Design
Pattern to do so. [L.O.1]
Writing space for the Problem:(For Student’s use only)

145
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

146
18SC2009R OBJECT ORIENTED PROGRAMMING

4. Rajesh wants to you to suggest him a movie to watch based on a list of 5 movies given
by him. He wants the criteria of suggestions to be rating, name and year of release.
Develop a program which sorts the movies by using all the three attributes individually
and prints them accordingly. (Use comparable interface) [L.O.3]
Writing space for the Problem:(For Student’s use only)

147
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

148
18SC2009R OBJECT ORIENTED PROGRAMMING

5. Riya is a bibliophile and wants you to develop a program which takes in 5 words from a
dictionary as dynamic user input and stores them in a Hashset. It should then print them
in lexicographical order. [L.O.2]
Writing space for the Problem:(For Student’s use only)

149
18SC2009R OBJECT ORIENTED PROGRAMMING

6. Stuti was asked to find maximum and minimum from a given set of numbers as her
assignment. Help her out by developing a program which takes in 10 numbers as a
dynamic user input and store them in a Hashset. Then it should sort the numbers and
print the maximum and minimum values from that list of numbers. [L.O.2]
Writing space for the Problem:(For Student’s use only)

150
18SC2009R OBJECT ORIENTED PROGRAMMING

7. Sara is the CEO of your company and wants to know about the various packages the
company is offering to the employees. You are asked by Sara to develop a program
which takes in the Salaries of 10 employees as Dynamic User Input and store them in a
Hashset. It should then print the various packages offered by the company in a sorted
order. [L.O.3]
Writing space for the Problem:(For Student’s use only)

151
18SC2009R OBJECT ORIENTED PROGRAMMING

8. Ram has a hobby of collecting coins. He loves collecting coins with different materials
like gold, silver, bronze, aluminum, etc. He visits his grandma’s home and finds a box
containing huge number of ancient coins. He then takes all of them and place them in
his collection. Later, he displays his collection to his family by picking the coins randomly
from his sack containing his collection. You are supposed to show the whole process by
displaying the random coins using Hashset. [L.O.2]
Writing space for the Problem:(For Student’s use only)

152
18SC2009R OBJECT ORIENTED PROGRAMMING

9. The details of enrolled students for JAVA Training session is to be maintained by the
Lecturer. He assigns you the task of creating it, asking you to create a class ‘Student’
taking in the required details of the student consisting Name, Id, Branch. You need to
explicitly convert the details in the class to the Hashset. Finally, the register should have
the details of Students in the ascending order of their ID numbers. Get this done by
using Hashset and comparable interface. [L.O.3]
Writing space for the Problem:(For Student’s use only)

153
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

154
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-11
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: To be able to use Treemap for real-world applications.
L.O.2: To be able to use Hashmap for real-world applications.

1) You are the head of your project team and are required to store the mail ID’s and ID
numbers of all your batchmates. Develop a program which takes in the details of the 7
team members as dynamic user input and store them in Hashmap. It should print the
details and it should also be able to help you search for a Mail ID using the ID number.
[L.O.2]
Writing space for the Problem:(For Student’s use only)

155
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

156
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Neha is working in the census department and wants to know the population details of
10 districts. Help her out by developing a program which takes in the name and
population of the districts as dynamic user inputs and stores them into a Treemap. It
should also be able to take in the name of a district from that list and print the districts
having lesser population than the given district. It should also be able to take in another
district and print the districts having greater population than given district. Also sort and
print the districts in descending order. [L.O.1]
Writing space for the Problem:(For Student’s use only)

157
18SC2009R OBJECT ORIENTED PROGRAMMING

3) Khyati is the Vijayawada railway station incharge and wants to digitalize the register for
the loco pilots and has asked you to develop a program which helps in doing so. It
should take in the details of 10 trains for that day (driver name, train number) as
dynamic user input and store them in a Hashmap. It should then be able to add the
details of a new loco pilot and his on-duty train number and also should be able to
delete an entry when needed. The program should also be able to update the details of
an entry if a loco pilot is on leave or if the train assigned to him is changed. [L.O.2]
Writing space for the Problem:(For Student’s use only)

158
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

159
18SC2009R OBJECT ORIENTED PROGRAMMING

4) Sowmya is the manager of the Indusland Bank and has asked you to develop a program
which takes in the details (account balance, customer name) of 5 customers as dynamic
user input and store them in a Treemap. It should then print the details in alphabetical
order of the accountant’s name. It should also give a feature to the customers where in
if three of them withdraw 1000/- and two of them deposit 1000/- it should then print
the updated balances along with their names. [L.O.1]
Writing space for the Problem:(For Student’s use only)

160
18SC2009R OBJECT ORIENTED PROGRAMMING

5) Nikhil is the class teacher of a section and wants to know the details of the student’s
grades in a subject. Develop a program which will help find out the number of students
in each grade by taking the scores of 15 students in that subject along with their roll
number as dynamic user inputs and store them into a Hashmap. Then it should
accordingly sort the student’s marks based on the grades they received and create a
new Hashmap for each grade. It should then count the number of students in each grade
and print their details individually in accordance to the grades. [L.O.2]

Marks Grade
85-100 O
80-84 A+
<80 A
Writing space for the Problem:(For Student’s use only)

161
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

162
18SC2009R OBJECT ORIENTED PROGRAMMING

6) Andrew is the librarian of your local library and wants to digitalize the process of storing
the details of the books present. Help him out by developing a program which takes in
the names and their ID’s of 10 books as dynamic user inputs and stores them into a
Treemap. It should then allow you to add details of new books and delete previous
book’s details if they’ve been replaced in the library. It should also display the details of
all the books present whenever necessary. Use Singleton Class to develop the program.
[L.O.1]
Writing space for the Problem:(For Student’s use only)

163
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

164
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Scott is incharge of all the workers in your mansion and wants your help to manage the
everyday tasks of all of them. Develop a program which’ll help him out by taking 6 tasks
along with the time consumed to complete the tasks as dynamic user inputs and store
them in a Treemap. It should then sort them in an ascending order of the time taken for
each task to be completed. [L.O.1]
Writing space for the Problem:(For Student’s use only)

165
18SC2009R OBJECT ORIENTED PROGRAMMING

8) You are a software developer and your client require a login page where user gives in
username and password. Create a login page using GUI in java. All the usernames and
passwords must be stored in a HashMap. If the credentials are valid, display the
message “Logged In”. If the credentials are invalid, display “Incorrect Credentials”.
[L.O.2]
Writing space for the Problem:(For Student’s use only)

166
18SC2009R OBJECT ORIENTED PROGRAMMING

9) Harika is a clothes merchant and wants to digitalize the process of displaying the various
models to the customers. Develop a menu driven program which takes in the dress
name and the cost of 15 types of clothes present in the shop as dynamic user inputs and
stores them in a Treemap. It should sort the clothes on the basis of their price in
ascending order, descending order, the order in which user gives the input and the
reverse order to the given input. [L.O.1]
Writing space for the Problem:(For Student’s use only)

167
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

168
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

169
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-12
Date of the Session: ___/___/___ Time of the Session:
_____to______

LEARNING OUTCOMES
L.O.1: Implement Stacks for real-world applications.
L.O.2: Implement Queues for real-world applications.
L.O.3: Implement Linked List for real-world applications.

1) Shreya was curious to know whether a word is a PALINDROME or not so, she wants you
to develop a program which takes a string as dynamic user input and stores it in a stack.
Then check whether it a palindrome or not. (Use Stacks concept only) [L.O.1]
Writing space for the Problem:(For Student’s use only)

170
18SC2009R OBJECT ORIENTED PROGRAMMING

2) You are a teacher in a class and want to print the ranks of 10 students who’ve written an
exam. Develop a program which takes in their name, ID number and marks as dynamic
user inputs. Each student’s details must be stored in a reference of a class and that
reference must be stored in a linked list. Print the ranks of all the students based on
their marks in descending order by only displaying their name and ID number. Use
comparable interface. [L.O.3]
Writing space for the Problem:(For Student’s use only)

171
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

172
18SC2009R OBJECT ORIENTED PROGRAMMING

3) Nina is looking for jobs and asked for your help to apply for a company. Develop a
program which takes in the names of 7 companies and their ratings as dynamic user
inputs and store it in a priority queue. Print the list of companies in descending order in
accordance with the rating. [L.O.2]
Writing space for the Problem:(For Student’s use only)

173
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

174
18SC2009R OBJECT ORIENTED PROGRAMMING

4) You are a game developer and are developing a level for an FPS game. Your gun in the
game has a magazine capacity of 10 bullets whose types you need to take in by dynamic
user input. Display the order in which the bullets will be fired. [L.O.1]
Writing space for the Problem:(For Student’s use only)

175
18SC2009R OBJECT ORIENTED PROGRAMMING

5) You are working on a thesis about the various Operating System’s invented till now and
want to develop a program which takes the name, founder and year of invention as the
dynamic user inputs. Each operating System’s details must be stored in a reference of a
class and that reference must be stored in a queue. Print the list of various Operating
System’s based on their year of founding in descending order by only displaying name
and founder. Use Comparable interface. [L.O.2]
Writing space for the Problem:(For Student’s use only)

176
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

177
18SC2009R OBJECT ORIENTED PROGRAMMING

6) Your company has developed a game and you are overseeing a contest being conducted
on it. As part of the contest, you need to develop a program which takes in the name
and the score of each gamer as dynamic user inputs and store them in a priority queue.
Print the rankings of the gamers by the end of the tournament in descending order in
accordance with their scores. Also print the winner. [L.O.2]
Writing space for the Problem:(For Student’s use only)

178
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

179
18SC2009R OBJECT ORIENTED PROGRAMMING

7) Smitha has gone on a holiday to Kashmir and was going through Jawaharlal Nehru
Tunnel (India’s Longest Tunnel) and gets struck in it due to an accident to a car in the
middle of the tunnel. She has been informed that all the cars must back away and exit
the tunnel without proceeding further. Develop a program to help the authorities find
out the flow with which the cars exit the tunnel. [L.O.1,3]
Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

180
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-13
Date of the Session: ___/___/___ Time of the Session:
_____to______

1) You have been given an assignment to take in 10 integers as dynamic user inputs and
count the number of positive and negative integers present. Also, calculate the total
and average of all the given numbers by using all the three loops (For, while, do-
while).
Writing space for the Problem:(For Student’s use only)

181
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

182
18SC2009R OBJECT ORIENTED PROGRAMMING

2) Ashley was given a task in class to take in 5 numbers as dynamic user inputs and
check which of the numbers are Harshad/Niven number and count the number of
Harshad numbers present. (Harshad number is a number that is divisible by the sum
of its digits)
Writing space for the Problem:(For Student’s use only)

183
18SC2009R OBJECT ORIENTED PROGRAMMING

3) NASA wants to measure the distance between Earth and Sun in light years which is
taken as dynamic user input and can’t be stored in primitive data types. Develop a
program which’ll find the sum of the digits of the numbers.
Writing space for the Problem:(For Student’s use only)

184
18SC2009R OBJECT ORIENTED PROGRAMMING

4) You have been approached by a client who owns a hospital to develop a program
which creates an outerclass Hospital having data fields hospitalName, hospitalAddr,
and gethospitalName() methodand an inner class Doctor having data field docName,
and setdocAddr(), getdocAddr()methods and access outer class members with inner
class by ’this’ keyword. create Democlass to complete the rest of the program.
Writing space for the Problem:(For Student’s use only)

185
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

186
18SC2009R OBJECT ORIENTED PROGRAMMING

5) You have been given a task to develop a program which has outer class OUTER and
Innerprivate class INNER which is used to display your name. Outer class contains a
method which is used to verify the PASSWORD entered by the user and if the
entered PASSWORD is correct, then call the inner class method to display your
name. Write a Demo class and make necessary calls to access OUTER and INNER
classes.
Writing space for the Problem:(For Student’s use only)

187
18SC2009R OBJECT ORIENTED PROGRAMMING

6) Your younger brother, Ankit was given a problem in his class to take in a string and a
floating-point number as dynamic user inputs. He comes up to you for help so
develop a program and print the floating point number up to two decimals and
upper case of the string in a single line using a single printf(),convert the floating
number to a string and print it using println(), now concat the both strings and print
it using print().
Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

188
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-14
Date of the Session: ___/___/___ Time of the Session:
_____to______

1. You have a screening test for the Interview of a Software Company. As a part of it,
you are asked to develop a program using the concept of Abstract class and
methods. Your program should perform the task of taking your interest for allowing
or denying your apps (such as Instagram or Facebook) to access your contacts,
media, messages, etc.
Writing space for the Problem:(For Student’s use only)

189
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

190
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

191
18SC2009R OBJECT ORIENTED PROGRAMMING

2. You are participating in a Quiz, and you need to solve the following snippet and
Guess the correct Output.

class A
{
int methodOfA (int i)
{
i /= 10;
return i;
}
}

class B extends A
{
int methodOfB (int i)
{
i *= 20;
return methodOfA(i);
}
}

public class MainClass


{
public static void main (String [] args)
{
B = new B ();
System.out.println(b. methodOfB (100));
}
}
Writing space for the Problem:(For Student’s use only)

192
18SC2009R OBJECT ORIENTED PROGRAMMING

3. Ranveer works for Indian Navy. He found the newly recruited and transferred
officers had a problem in finding their work hours. So, let us help Ranveer to solve
this problem faced by officers of Indian Navy by implementing a java program that
uses the concept of inheritance, which takes in the input of your designation and
displays the number of hours.
Writing space for the Problem:(For Student’s use only)

193
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

194
18SC2009R OBJECT ORIENTED PROGRAMMING

4. The Vallabhapuram mandal conducts running competition every year as a part of


village fair. The village chief is fond of the number ‘5’, and so he wished to give prizes
to the participants who got first and fifth place. He asks his son to write a program
such that it displays the names of the people who came at 1st and 5th positions.
Now chief is invited to judge a race in his neighboring village but there are only ‘four’
participants in the race. Now help the chief to display only first place person’s name
by correcting the program with exception handling while also displaying the
exception.
Hint: Array Index out of Bond.
Writing space for the Problem:(For Student’s use only)

195
18SC2009R OBJECT ORIENTED PROGRAMMING

5. You have been asked by your faculty to develop a program which contains two
classes generateInteger and generateDouble and these both classes implement a
method generator in the interface Generator. Make sure the method generator
prints three random integers in generateInteger class and three random double
values in class generateDouble.
Writing space for the Problem:(For Student’s use only)

196
18SC2009R OBJECT ORIENTED PROGRAMMING

6. Your mathematics faculty has asked for your help in order to convey a statement to
certain set of students. Develop a program which helps him to convey the line ‘Area
and perimeter can be implemented for 2D figures and Area and Volume can be
implemented for 3D figures.
Hint- Use Area volume and perimeter as three different interfaces and classes 2D
and 3D to implement those interfaces.

Writing space for the Problem:(For Student’s use only)

197
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

198
18SC2009R OBJECT ORIENTED PROGRAMMING

7. Chinnu’s mother asked him to go to the shop and get some groceries and he wanted
to store all the list of groceries to get a clarity on bill. He ate an Ice cream on the way
and spent some money. After he got the groceries into the basket, he found that he
doesn’t have enough amount to get all the items, so he removed a few items in the
list considering the available amount. Now display the both lists, before and after
removing the items by using vector method and create the second list by using
cloning method?

Writing space for the Problem:(For Student’s use only)

199
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

200
18SC2009R OBJECT ORIENTED PROGRAMMING

8. The Owner of a Supermarket asks the Employee to maintain a detailed record


consisting Name, Id and Cost of the item available in their supermarket. He also asks
him to get the information of those items in ascending order of the costs. He asks
your help for writing a program which takes in the details through the Scanner class
and add them to the array list. Your program should also display the details of the
items compared in ascending order of the item cost. (Use list and Comparable
interface)

Writing space for the Problem:(For Student’s use only)

201
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

202
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

203
18SC2009R OBJECT ORIENTED PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


SUBJECT CODE: 18SC2009R
OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB EXPERIMENT-15
Date of the Session: ___/___/___ Time of the Session:
_____to______

1. Sahithi was asked to find descending order of the given set of numbers as her
Assignment. Help her out by developing a program which takes in 10 numbers as a
dynamic user input and store them in a Hash set. Then it should sort the numbers
and print them in descending order.
Writing space for the Problem:(For Student’s use only)

204
18SC2009R OBJECT ORIENTED PROGRAMMING

2. Priya wants you to develop a program which takes in words from a dictionary as
dynamic user input and stores them in a Hashset. It should then print them in
lexicographical order after converting Hashset into Treeset.
Writing space for the Problem:(For Student’s use only)

205
18SC2009R OBJECT ORIENTED PROGRAMMING

3. Elsa was asked to develop a program which takes in five numbers as dynamic user
input and stores them in an Hashset. He passes the Hashset to two threads. First one
should traverse the set, and the Even numbers present in it should be printed and
the second thread should print the Odd numbers present in the set. Help him out by
writing the program using Runnable Interface.
Writing space for the Problem:(For Student’s use only)

206
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

207
18SC2009R OBJECT ORIENTED PROGRAMMING

4. Sowmya was asked to develop a program which takes a no. of Login Credentials as a
dynamic user input and stores them in a HashMap. The User who wants to Login
should provide the credentials in the GUI Login form. If the credentials provided
matches with one of the credentials in the HashMap, then the User Successfully
logins. If the User logins Successfully, then the background color changes to red
color.
Writing space for the Problem:(For Student’s use only)

208
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

209
18SC2009R OBJECT ORIENTED PROGRAMMING

5. Mihir was asked to develop a game based on stacks. There will be two players in the
game. Every player will get a turn to enter a number and that number will be pushed
into a stack if the given number is divided by a number which is randomly generated
by the game otherwise the top element of the stack will be popped out. The player
whose is left with no numbers in the stack is the loser. Print the Winner of the game.
Writing space for the Problem:(For Student’s use only)

210
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

211
18SC2009R OBJECT ORIENTED PROGRAMMING

6. Riya wants to develop a Movie Booking site. This site should have the options of
Ticket Booking and Cancellation. Before booking, the user should provide the details
like name, email id and phone number. A booking Id will be generated automatically
for the user to book tickets. If the no. of Tickets requested by the user are available,
then the user will be placed on Confirmation queue, else the user will be placed on
Waiting queue. If any user cancels his booking based on booking the cancelled user
details will be printed and the users in the waiting queue will be moved to
Confirmation queue based on the requirement of tickets. Help him out writing the
program.
Writing space for the Problem:(For Student’s use only)

212
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

213
18SC2009R OBJECT ORIENTED PROGRAMMING

7. Rohit was a seasoned traveler. He liked to visit new places. More than all he was a
meticulous planner. This time he was planning to visit Europe. He wrote down his
travel itinerary like as follows: If he wanted to visit Madrid, Paris, Munich, Warsaw
and Kiev in this order, he would write it down like as:

Madrid Paris 100 Paris Munich 200


Munich Warsaw 150 Warsaw Kiev 120
More formally, if he wanted to go from A to B directly and the price is C dollars, then
he would write (A B C$) on a card. Each move was written on a different card. Rohit
was a great planner, so he would never visit the same place twice. Just before
starting his journey, the cards got shuffled. Help Rohit figure out the actual order of
the cards and the total cost of his journey using HashMap concept.
Writing space for the Problem:(For Student’s use only)

214
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

215
18SC2009R OBJECT ORIENTED PROGRAMMING

8. Sravya wants to develop an app which sorts the Train Ids based on destination time.
The User provides the destination times of different trains along with Train Ids and
stores them in a HahMap.Help him out writing the program to develop the app.

Writing space for the Problem:(For Student’s use only)

216
18SC2009R OBJECT ORIENTED PROGRAMMING

Writing space for the Problem:(For Student’s use only)

(For Evaluator’s use only)

Comment of the Evaluator (if Any) Evaluator’s Observation


Marks Secured: _______ out of ________

Full Name of the Evaluator:

Signature of the Evaluator Date of Evaluation:

217
18SC2009R OBJECT ORIENTED PROGRAMMING

Evaluation sheet for Skilling

Sl.No Date No of Marks Faculty Remarks


Problems Signature
solved

10

218

Potrebbero piacerti anche