frist oom lab assignment2014
TRANSCRIPT
-
8/12/2019 Frist OOM Lab Assignment2014
1/2
Indian Institute of Information Technology, Allahabad
Object Oriented Methodology (OOM)
Lab Assignment-1
TAs !harat "ingh, #idhi $ush%aha, Moni&a 'ani, Arit, Anand, 'eju, "atish
ate of assignment 1*++.1/ ue ate ++.1/ Instructors 0rof O 0 2yas and r 'anjana 2yas
#ote
1) All Assignments should be done indeendently
) Try to de3elo Object Oriented Thin&ing for the roblem gi3en
4) 5rite simle code in ja3a for rinting aroriate 3alues
/) 0reare a coy and %rite source code along %ith inut and outut for e3ery
rogram gi3en in the OOM lab
*) 'eady for line-by-line e6laination of your code running on your system
71. Write a user-defined function to find the sum of an array passed as argument. Write a program
that declares an array of 10 elements and uses this function to
a. Find the sum of all elements
b. Find the sum of first 5 elements
c. Find the sum of last 5 elements.
7. Define a class of type Student that has Rollno., name and age as priate data members. Define
SetData!" and #etData!" as public member functions $ith appropriate functionality. Write a programthat declares % student ob&ects, initiali'es the first at run-time and second by reading from console,
and then displays both student(s data.
74. Write &aa code for the follo$ing scenario)-
a. Demonstrate the access specifiers public and default $ith the student class in program 5 and also
demonstrate that other access specifiers !protected and priate" can(t be used $ith class.
b. *reate 5 *lasses + , , *, D, according to the diagram. Demonstrate the use of all access
specifiers !public, protected, default and priate" $ith the data members of class in other classes.
c. /odify program 5 to add another array member mars to the class that stores mars of 5 sub&ects
and then re$or $ith the program.
7/. Define a class of type Distance that has Feet and nches as members. Define a function that
adds t$o Distances passed as argument and returns the sum as another Distance ob&ect. 2lace the
class in a pacage named user.o$n.pac . *ompile and run the &aa file using console !&aac and &aa
utility".Write a program that imports this pacage and uses class to find the sum of t$o distances.
-
8/12/2019 Frist OOM Lab Assignment2014
2/2
7*. Design a ne$ class called 3*ode4imer. 4his class should contain the follo$ing data fields)
a. priate long alue named start4ime
b. priate long alue named end4ime
c. #et methods for both start4ime and end4ime !i.e. getStart4ime!" andgetnd4ime!"
d. no argument constructor that initiali'es start4ime $ith the current time !hint)
use System.current4ime/illis!" "
e. method named start!" that resets that start4ime to the current time
f. method named stop!" that sets the end4ime to the current time
g. method named getlapsed4ime!" that returns the elapsed time bet$een
start4ime and end4ime.