Professional Documents
Culture Documents
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
LabManual
ObjectOrientedProgrammingwithJAVA
(15ECSP203)
201617
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
Sl.No.
Contents
1.
CourseOutcomes(COs)
2.
ListofExperiments
3.
IntroductiontoObjectOrientedProgramming
4.
StandardOperatingProcedure
5.
JavaTools
ProceduretoCreateandExecuteJavaProjectinEclipseIDE
7.
ExampleforExperiments
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
CourseOutcomes(COs)
Attheendofthecoursethestudentshouldbeableto:
1. ApplyObjectOrientedProgrammingconceptstosolveagivenproblem.
2. Applydesignpatternstodesignasolutionforagivenproblem.
3. Apply inheritance, polymorphism and exception handling mechanism to implement
reusable,robustjavaprograms.
4. Performunittestingforanidentifiedmethod/methodsofaclass/classes.
5. Implementuserinterfacejavaprogramsforagivenscenario.
ListofExperiments
Sl.
No.
Category
Topicsforexperimentstobeconductedundereach
category
Arrays,StringsandStringBuffer
1.
Exercises
ClassesandObjects
InheritanceandPolymorphism
RuntimeErrorManagement:ExceptionHandling
ClassesandObjects
2.
StructuredEnquiry
InheritanceandPolymorphism
RuntimeErrorManagement:ExceptionHandling
GUIDesignandEventHandling
3.
OpenEnded
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
IntroductiontoObjectOrientedProgramming
The object oriented paradigm is built on the foundation laid by the structured
programmingconcepts.ThefundamentalchangeinOOP(ObjectOriented Programming)isthat
a program is designed around the data being operated upon rather upon the operations
themselves.Dataanditsfunctionsareencapsulatedintoasingleentity.OOPfacilitatescreating
reusable code that can eventually save a lot of work. A feature called polymorphismpermitsto
createmultipledefinitionsforoperatorsandfunctions.Anotherfeaturecalledinheritancepermits
to derive new classes from old ones. OOP introduces many new ideas and involvesadifferent
approachtoprogrammingthantheproceduralprogramming.
Benefitsofobjectorientedprogramming
Datasecurityisenforced(DataCentric).
Inheritancesavestime(Reusability).
Userdefineddatatypescanbeeasilyconstructed.
Largecomplexityinthesoftwaredevelopmentcanbeeasilymanaged.
StandardOperatingProcedure
The Standard Operating Procedure (SOP) defines how the laboratory course is conducted for
ObjectOrientedprogrammingwithJAVAlabanditisdefinedbythefollowingsteps.
1. The student has to come to lab with class notes and it is used as a ready referencefor
theconceptsdiscussedintheclassroom.
2. The first activity for the student is to practice the class roomprograms(code)andverify
theprogramswithdifferenttestcases.
3. All the students once complete the class room programs, they will be given an
assignment and it is individual activity. This assignment test the ability of the student to
apply the concepts taught in the class room. This assignment is guided assignment
wherethestudentisassistedondemand,insolvingtheproblem.
4. The step 3 is optional and all the students are evaluated as per the category of
experiments.
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
Evaluation
StudentsAssessmentThroughISA(80%)+ESA(20%)
InternalSemester
Assessment(80%)
Assessment
Marks
Exercises
40
StructuredEnquiry
20
OpenEndedandCourseActivity
20+5*
SemesterEndAssessment(20%)
20
TOTALMARKS
100+5*
*IndicatesmarksfromtheoryCIE.
JavaTools
Thestudentswillbeintroducedtothefollowingtopics
Introductiontothejavaenvironment
UseofIDE(Eclipse)
Definingsimpleclassesandcreatingobjects.
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
ProceduretoCreateandExecuteJavaProjectinEclipseIDE
1. ChooseFileNewJavaProjectfromtheEclipsemenubar,asinthefollowing
example:
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
3. If you click the "Configure default..." link in the "Project Layout" area, you can make
these settings your default settings for new projects. Select "Project" for the "Source
and output folder" option and click "OK" button. Werecommendthatstudentsconfigure
Eclipseinthisway.
4. After returning to the New Project Wizard dialog box, click Finish to actually create the
project you just described. The followingscreenwillbedisplayed,denotingaworkspace
withoneprojecttochoosefromthePackageExplorer:
Note: If you forgot to close the Welcome screen (shown in the prior step), thenyouwill
not see the above window.ToclosetheWelcomescreen,clicktheXonthetablabeled
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
Welcome (towards the top left of the Eclipse window). Now you should see the
workspace.
5. Congratulations, you have created your firstJavaproject!But,we'reonlypartwaythere.
Nextcomesputtingsomesubstance(code)intotheprojecttomakeaworkingprogram!
6. We need to create a source file where we will write our program. Rightclick on the
"HelloWorld" project in the Package Explorer tabbed pane on the left side ofthescreen
andnavigatetoNewClass,asinthefollowingexample:
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
Click Finish. This step will create a new file named HelloWorld.java and add it to the
project for you.ItwillalsoopenatabbedwindowwhereyoucanedittheHelloWorld.java
sourcefile.
8. Now that we've completed the setup we can write the program. Enter the following text
intotheHelloWorld.javawindow.
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
access theHelloWorld.java file. Rightclick on the file and select Run As Java
Application.
ExampleforExperiments
1. Design java application to model Employee of an ABCorganization.Considertypesof
employeesas
a. Manager
b. SalesPerson
Performthefollowing
a. Implement simple inheritance where Employee (employee ID, First Name, Last
Name, Current salary) is super class, consider Manager (number of stock
options)andSalesPerson(numberofsales,commissionrate)assubclasses.
b. Defineparameterizedconstructorsinclasshierarchy.
c. Define methods to display status of employee (override toString() )andincrease
currentpayment(salary)asgivingbonusbyasmallamount.
d. Identify the different options of giving bonus (to increase current pay by small
amount) and consider type of employee whilegivingbonus.Applypolymorphism
formethodsusinginheritanceinclasshierarchy.
e. Create an array of super class variables and populate array with sub class
objects.Callmethodsusingarrayofobjects.
2. Create class Employee with name, Id, cellNum, designation, department, salary
permanent(boolean)asmembers.Also
3. CreateasuperclassBindu{x,y}andsubclassBindu3d{z}
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
a. includeaparameterizedconstructorinclassBindutoinitializeobject.
b. include a method in class Bindu to print data members of object. Override the
samemethodinsubclassandreusetheinheritedmethodinit
c. Create final static member printArr (Bindu[ ]) which print array of objects. In this
methoduseabovemethodtoprintmemberofindividualobjectsofarray.
d. Write test class tocreatetoarrayofBindu3dtype.Usetheabovemethodtoprint
alltheobjectsofarray.
4. A bank maintains two kinds of accounts Savings account and Current account. The
savings account provides simple interest, deposit and withdrawal facilities. The current
account only provides deposit and withdrawal facilities. Current account holders should
also maintain minimumbalance.Ifbalancefallsbelowminimumlevelaservicechargeis
imposed. Create an abstract class Account thatstorescustomername,accountnumber
typeofaccountandabstract methods. From this derive the classes Curr_Account
(doublebalance,doublemin_bal,doubleserviceCharge/penalty)andandSav_Account
(double balance). Include the necessary methods in order to achieve the
following:
a. Defineparameterizedconstructorinaclasshierarchy.
b. Allowdepositandupdatethebalance.
c. Displaythebalance.
d. Computeinterestandaddtobalance.
e. Permit withdrawalandupdatethebalance(checkforminimumbalance).
f.
Applypolymorphismifrequiredformethodsinclasshierarchy.
g. Create an array of super class / object and populate with subclass objects and
calltheoverridden/objectmethods.
h. Writeatestprogramtodemonstratetheabovesaidimplementations.
KLESociety's
KLETechnologicalUniversity
SCHOOLOFCOMPUTERSCIENCE&ENGG
a. Defineappropriateconstructorsinaclasshierarchy.
b. Ensure the bonus amount should not be negative and zero using exception
handlingmechanism(usethrowsandthrowclausesofexceptionhandling).
c. Createarrayofinterfacereferencevariablesandpopulatewithmanagerobjects.
d. Write a test program to implement the above said requirements of interface
implementationandexceptionhandling.
created and stored as objects. Also include a feature to search customer based on
accountnumber.
8. Create a window to input minor1, minor2 and assignment marks forastudentandstore
it as object, also provide feature to display total marks of each student and number of
studentsineachgrade.
9. Write a java program to accept user name in a text box. Accept the class of the user
(Faculty, student, admin etc.,) using radio buttons and the hobbies of the user using
checkboxes.Displaytheselectedoptionsinatextarea/textbox.
10. Simulate loan application. The loans are four wheeler loan and two wheeler loan. The
application has to provide functionality to calculate EMI, pay EMI and display the
customer details along with his loan details till he clearstheloan.Therateofinterestfor
two wheeler loan changes from lower to higher value, the applicationshouldupdatethe
changes. Consider some collection (array) to store different loan objects. Define
appropriate classes, constructors, objects and other constructs to complete the
implementation.