You are on page 1of 9

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SUBJECT CODE: 17CS2004


OBJECT ORIENTED PROGRAMMING WORKBOOK

LAB-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)


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)
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)
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)
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)
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)

You might also like