Date post: | 01-Jul-2018 |
Category: |
Documents |
Upload: | truongnguyet |
View: | 416 times |
Download: | 7 times |
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Lab Manual
Object Oriented Programming with JAVA
(15ECSP203)
2016 17
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Sl. No. Contents
1. Course Outcomes (COs)
2. List of Experiments
3. Introduction to Object Oriented Programming
4. Standard Operating Procedure
5. Java Tools
6 Procedure to Create and Execute Java Project in Eclipse IDE
7. Example for Experiments
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Course Outcomes (COs) At the end of the course the student should be able to:
1. Apply Object Oriented Programming concepts to solve a given problem.
2. Apply design patterns to design a solution for a given problem.
3. Apply inheritance, polymorphism and exception handling mechanism to implement
reusable, robust java programs.
4. Perform unit testing for an identified method/methods of a class/classes.
5. Implement user interface java programs for a given scenario.
List of Experiments
Sl. No. Category Topics for experiments to be conducted under each
category
1. Exercises
Arrays, Strings and StringBuffer
Classes and Objects
Inheritance and Polymorphism
Runtime Error Management : Exception Handling
2. Structured Enquiry
Classes and Objects
Inheritance and Polymorphism
Runtime Error Management : Exception Handling
GUI Design and Event Handling
3. Open Ended Problem domain will be given to a group of students, which is based on the exercises of the laboratory course. Implementation has to be carried out in the laboratory.
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Introduction to Object Oriented Programming
The object oriented paradigm is built on the foundation laid by the structured
programming concepts. The fundamental change in OOP (Object Oriented Programming) is that
a program is designed around the data being operated upon rather upon the operations
themselves. Data and its functions are encapsulated into a single entity. OOP facilitates creating
reusable code that can eventually save a lot of work. A feature called polymorphism permits to
create multiple definitions for operators and functions. Another feature called inheritance permits
to derive new classes from old ones. OOP introduces many new ideas and involves a different
approach to programming than the procedural programming.
Benefits of object oriented programming ● Data security is enforced (Data Centric).
● Inheritance saves time (Reusability).
● User defined data types can be easily constructed.
● Large complexity in the software development can be easily managed.
Standard Operating Procedure
The Standard Operating Procedure (SOP) defines how the laboratory course is conducted for
Object Oriented programming with JAVA lab and it is defined by the following steps.
1. The student has to come to lab with class notes and it is used as a ready reference for
the concepts discussed in the class room.
2. The first activity for the student is to practice the class room programs (code) and verify
the programs with different test cases.
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
where the student is assisted ondemand, in solving the problem.
4. The step 3 is optional and all the students are evaluated as per the category of
experiments.
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
5. Evaluation procedure : The student has to first submit the written proposed solution for
a given problem statement and it is verified (evaluated as per the rubrics) by the faculty
then the student can type the code and demonstrate.
Evaluation
Students Assessment Through ISA (80%) + ESA (20%)
Assessment Marks
Internal Semester Assessment (80%)
Exercises 40
Structured Enquiry 20
Open Ended and Course Activity 20 + 5*
Semester End Assessment (20%) 20
TOTAL MARKS 100 + 5* * Indicates marks from theory CIE.
Java Tools
● The students will be introduced to the following topics
● Introduction to the java environment
● Use of IDE (Eclipse)
● Defining simple classes and creating objects.
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Procedure to Create and Execute Java Project in Eclipse IDE 1. Choose File → New → Java Project from the Eclipse menu bar, as in the following
example :
2. The following window will be displayed. Enter the Project name and make sure the "Use
Project folder as root for sources and class files" option is selected in the "Project layout"
section as shown in the image below:
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & 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. We recommend that students configure
Eclipse in this way.
4. After returning to the New Project Wizard dialog box, click Finish to actually create the
project you just described. The following screen will be displayed, denoting a workspace
with one project to choose from the Package Explorer:
Note: If you forgot to close the Welcome screen (shown in the prior step), then you will
not see the above window. To close the Welcome screen, click the X on the tab labeled
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Welcome (towards the top left of the Eclipse window). Now you should see the
workspace.
5. Congratulations, you have created your first Java project! But, we're only part way there.
Next comes putting some substance (code) into the project to make a working program!
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 of the screen
and navigate to New → Class, as in the following example:
7. Another window will be displayed. Then click in the text box labeled "Name:" and type in
HelloWorld, as in the following example:
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
Click Finish. This step will create a new file named HelloWorld.java and add it to the
project for you. It will also open a tabbed window where you can edit the HelloWorld.java
source file.
8. Now that we've completed the setup we can write the program. Enter the following text
into the HelloWorld.java window.
9. Go to the left Package Explorer pane. The HelloWorld folder should be opened, but if it
is not, doubleclick on folder to open it. Then, double click on the "(default package)" to
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
access theHelloWorld.java file. Rightclick on the file and select Run As → Java
Application.
Example for Experiments
1. Design java application to model Employee of an “ABC” organization. Consider types of
employees as
a. Manager
b. Sales Person
Perform the following a. Implement simple inheritance where Employee (employee ID, First Name, Last
Name, Current salary) is super class, consider Manager (number of stock
options) and SalesPerson (number of sales, commission rate) as subclasses.
b. Define parameterized constructors in class hierarchy.
c. Define methods to display status of employee (override toString() ) and increase
current payment (salary) as giving bonus by a small amount.
d. Identify the different options of giving bonus (to increase current pay by small
amount) and consider type of employee while giving bonus. Apply polymorphism
for methods using inheritance in class hierarchy.
e. Create an array of super class variables and populate array with sub class
objects. Call methods using array of objects.
2. Create class Employee with name, Id, cellNum, designation, department, salary
permanent (boolean) as members. Also create separate class for member name as
EmpName, department as Department and salary as Salary. Members of EmpName
are firstName, midName, lastName . Members of Salary are basic, daPercent, hra , pf,
insurance. Members of Department are deptName,deptCode. Create an instance of Employee and initialize all its members from user input console.
Access the same instance by more than one reference of Employee. Count the number
of references and objects being created. [class,references,objects].
3. Create a super class Bindu {x,y} and subclass Bindu3d {z}
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
a. include a parameterized constructor in class Bindu to initialize object.
b. include a method in class Bindu to print data members of object. Override the
same method in subclass and reuse the inherited method in it
c. Create final static member printArr (Bindu[ ]) which print array of objects. In this
method use above method to print member of individual objects of array.
d. Write test class to create to array of Bindu3d type. Use the above method to print
all the objects of array.
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 minimum balance. If balance falls below minimum level a service charge is
imposed. Create an abstract class Account that stores customer name, account number
type of account and abstract methods. From this derive the classes Curr_Account
(double balance, double min_bal, double serviceCharge / penalty) and and Sav_Account
(double balance). Include the necessary methods in order to achieve the
following:
a. Define parameterized constructor in a class hierarchy.
b. Allow deposit and update the balance.
c. Display the balance.
d. Compute interest and add to balance.
e. Permit withdrawal and update the balance (check for minimum balance).
f. Apply polymorphism if required for methods in class hierarchy.
g. Create an array of super class / object and populate with subclass objects and
call the overridden / object methods.
h. Write a test program to demonstrate the above said implementations.
5. Define a interface EMPInterface (void displayEMP(), void giveBonus (double amount)).
Define an abstract class Employee(empID, fName, lName, salary). Define a concrete
class Manager (noOfOtockOptions), subclass of Employee and define interface
methods.
Perform the following
KLE Society's KLE Technological University
SCHOOL OF COMPUTER SCIENCE & ENGG
a. Define appropriate constructors in a class hierarchy.
b. Ensure the bonus amount should not be negative and zero using exception
handling mechanism (use throws and throw clauses of exception handling).
c. Create array of interface reference variables and populate with manager objects.
d. Write a test program to implement the above said requirements of interface
implementation and exception handling.
6. Create an interface mobilePhone {makeAudioCall (string ellNum), makeVideoCall (string
cellNum), Boolean isCamerFeatured()}
a. Create a subclass BudgetPhone, smartPhone and implement methods
appropriately.
b. Create an exception class cameraNotfound use it handle exception when a video
call attempt is made on noncamera phone. In such case audio call should be
made to handle such exceptions.
7. Create window through which an account of a customer for a bank can be
created and stored as objects. Also include a feature to search customer based on
account number.
8. Create a window to input minor1, minor2 and assignment marks for a student and store
it as object, also provide feature to display total marks of each student and number of
students in each grade.
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. Display the selected options in a textarea/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 clears the loan. The rate of interest for
two wheeler loan changes from lower to higher value, the application should update the
changes. Consider some collection (array) to store different loan objects. Define
appropriate classes, constructors, objects and other constructs to complete the
implementation.