LAB Manual: Course: CSC241-Object Oriented Programming
LAB Manual: Course: CSC241-Object Oriented Programming
MANUAL
Course: CSC241-Object Oriented Programming
Learning Procedure
1) Stage J (Journey inside-out the concept)
2) Stage a1 (Apply the learned)
3) Stage v (Verify the accuracy)
4) Stage a2 (Assess your work)
Statement Purpose:
Objective of this lab is to make students understand the difference between object oriented and
procedural approaches to programming
Activity Outcomes:
The student will understand the advantages of using OOP
The student will understand the difference between procedural and object oriented approaches
Instructor Note:
The Students should have knowledge about structured programming.
2) Stage a1 (apply)
Lab Activities:
Activity 1:
The example demonstrates the difference in approach if we want to find the circumference of
circle.
Solution:
Procedural Approach Object Oriented Approach
Public class Circle{ Public class Circle{
int radius; Private int radius;
Public void setRadius(int r) Public void setRadius(int r)
{ radius = r;} { radius = r;}
Public void showCircumference() Public void showCircumference()
{ {
double c = 2*3.14*radius; double c = 2*3.14* radius;
System.out.println(“Circumferenceis”+ c); System.out.println(“Circumference is”+
} c);
Public static void main() }
{ }
setRadius(5); Public class runner
showCircumference(); {
//output would be 31.4 Public static void main()
setRadius(10); {
showCircumference(); Circle c1= new circle();
// output would be 62.8 c1.setRadius(5);
} c1.showCircumference();
} //output would be 31.4; it belongs to c1
Circle c2= new circle();
c2.setRadius(10);
c2.showCircumference();
//output would be 62.8; it belongs to c2
}
}
Activity 2:
The example demonstrates the difference in approach if we want to model the concept of a
Book. In object Oriented approach the concept can be defined once and then reused in form
of different objects.
//output belongs to b2
}
}
Activity 3:
The example demonstrates the difference in approach if we want to model the concept of an
Account. Again we can see that in object Oriented approach the concept can be defined once
and then reused uniquely by different objects.
}
}