0% found this document useful (0 votes)
10 views1 page

Lab Assignment 4

Uploaded by

amank1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
10 views1 page

Lab Assignment 4

Uploaded by

amank1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

CSN-103: Fundamentals of Object Oriented Programming

Assignment 04

General Instructions:
a) Use Scanner class whenever required to accept inputs for the user at the runtime.
b) DO NOT ATTEMPT TO CHEAT. YOU WILL BE SEVERELY PENALIZED.
c) Use of internet is not allowed. You can refer to your class notes.
d) Make sure your TA records your marks after evaluation. Request for evaluation after the lab
session will not be entertained.
e) Follow indentation while writing programs.

Programming Problems
1) Write a JAVA program that accepts 3 command-line arguments in the following sequence:
Operand Operator Operand and perform the arithmetic operation specified by the Operator.
For example, if three command-line arguments are 4 + 5 then 9 should be printed on the screen.
Program should work for the following operators: +, -, *, /, %
2) Write a JAVA program with the following two methods: ctain() and ccat(). ctain() should
provide the same functionality as contains() method and ccat() should provide the same
functionality as concat() method available in the String class. [Link]
3) Write a JAVA program to create a class point having two member variables; x_coordinate and
y_coordinate. Create two objects of the point class and initialize them with random double values
using a constructor. Finally, write a method findDistance() to calculate the distance between
these two point objects.
4) Write a JAVA program to add two timestamps using a class. Timestamp is of the form
Hour:Minutes:Seconds. Accept one timestamp using Scanner and initialize the second timestamp
using a constructor. For example, given two timestamps 08:20:46 and 12:24:34, the resultant time
will be 20:45:20.
5) Write a JAVA program to create a class Rectangle having two member variables viz., length and
width, and a method called calculate(). The class should contain three constructors:
a. Default constructor: Initializes the length and width to 0.
b. Constructor with one int parameter: Initializes both length and width equal to the value of
the int parameter.
c. Constructor with two double parameters: Initializes length and width equal to the value of
first and second parameter, respectively.
Create three objects of Rectangle class using the above constructors and print the area by calling the
calculate() method for each object.

You might also like