You are on page 1of 25

HND (HIGHER NATIONAL DIPLOMA)

Object Oriented Programming


Assignment 1

Rajendra Paudel
Queensland College
Dec 2010

1
Acknowledgement

First and foremost, I would like to express my gratitude to my lecturer of this


assignment, Mrs. Prerna Kanwar for the valuable suggestions, guidance and advice.
She inspired and motivates me greatly to complete this assignment. I also would like
to thank him for showing me some example that related to the topic of my
assignment.

Besides, I would like to thank the authority of Queensland College for providing me
with a good environment and facilities to complete this assignment. In addition, I
would also like to thank all of my friends who provide me valuable information as the
guidance of my assignment.

Finally, an honourable mention goes to my wife Mrs Sandhya Paudel for her help,
understandings and supports on me in research and completing this assignment.

2
Table of Contents

Content Page No

Introduction 4

Procedural Programming Language 4


Object Oriented Programming 5
CRC Design Method 10
Class Diagram 13
CRC using Java Structure 15
Requirement for JAVA 18
Role of Class Library in Java 22
Abstract Windowing Toolkit (AWT) 22
Java Applet 22
References 25

3
Introduction

The West London College is a newly opened FE college with 200students and 20
Lectures. The college recruits both part time and fulltime students. The College wants
to record all the student’s personnel information like their name, address, contact
number, email address during the time of the registration and assigned a unique
Student ID number for each student who can only enrol in one course as full time or
part time student and has to pay their course fees during enrolment either full or
instalments basis. Besides this college wants to record information for lecturers and
assigned a unique ID for them and they must teach one or more module, which has its
own code, name and information. A course is identified by its unique ID number,
which assigned start date and end date and is usually delivered over three working
days of the week and has many modules.

Any programming languages may implement to design a program for West London
College and can solve a problem. Any problem that can be solved using one
programming language may also be solved using any other programming
language. However, there will be huge variations in the sizes of these programs, how
much it cost, how long it take to develop, how reliably accurate they are, and in their
execution speeds. Among the programming language a Procedural Language
Programming or Object Oriented Programming can be used for College.

Procedural Programming Language:

Procedural language, a term used in contrast to declarative language, describes a


language where the programmer specifies an explicit sequences of steps to follow to
produce a result. Common procedural languages include Basic, Pascal, C and
Modula-2.

In a procedural-based programming language, a programmer writes out instructions


that are followed by a computer from start to finish, which is also called a Top Down
Design. This starts with a problem and then systematically breaks the problem down
into sub problems called functional decomposition, which continues until a sub
problem is straightforward enough to be solved by the corresponding sub procedure.

4
Advantages of Procedural Programming
• Its relative simplicity, and ease of implementation of compilers and
interpreters
• The ability to re-use the same code at different places in the program without
copying it.
• An easier way to keep track of program flow.
• The ability to be strongly modular or structured.
• Needs only less memory.
Limitation of Procedural Language
• Procedural programming tends to be relatively low level compared to some
other paradigms, and as a result can be very much less productive. .
• The software maintenance can be difficult and time consuming.
• When changes are made to the main procedure, the change may impact all procedures
in the pyramid
• Difficult to identify the errors.
• If any modifications are there in the code it is difficult to modify.
• Less flexible

Object Oriented Programming

SIMULA was the first object language. As its name suggests it was used to create
simulations. The idea of object-oriented programming gained momentum in the 1970s
and in the early 1980s Bjorn Stroustrup integrated object-oriented programming into
the C language. The resulting language was called C++ and it became the first object-
oriented language to be widely used commercially.In the early 1990s a group at Sun
led by James Gosling developed a simpler version of C++ called Java that was meant
to be a programming language for video-on-demand applications..

Object-oriented programming is a programming paradigm that uses abstraction (in


the form of classes and objects) to create models based on the real world
environment. An object-oriented application uses a collection of objects, which
communicate by passing messages to request services. Objects are capable of passing
messages, receiving messages, and processing data. The aim of object-oriented
programming is to try to increase the flexibility and maintainability of
programs. Because programs created using an OO language are modular, they can be
easier to develop, and simpler to understand after development.

5
The following statement defines an object oriented programming language:

Object-oriented language = Object-based features + Inheritance + Polymorphism


Concepts of OOP
• Objects
• Classes
• Data Abstraction and Encapsulation
• Inheritance
• Polymorphism
Objects

Objects are the basic run-time entities in an object-oriented system. Programming


problem is analyzed in terms of objects and nature of communication between them.
When a program is executed, objects interact with each other by sending messages.
Different objects can also interact with each other without knowing the details of their
data or code.

Classes

A class is a collection of objects of similar type. Once a class is defined, any number
of objects can be created which belong to that class.

Data Abstraction and Encapsulation

Abstraction refers to the act of representing essential features without including the
background details or explanations. Classes use the concept of abstraction and are
defined as a list of abstract attributes. Storing data and functions in a single unit
(class) is encapsulation. Data cannot be accessible to the outside world and only those
functions which are stored in the class can access it.

6
Inheritance

Inheritance is the process by which objects can acquire the properties of objects of
other class. In OOP, inheritance provides reusability, like, adding additional features
to an existing class without modifying it. This is achieved by deriving a new class
from the existing one. The new class will have combined features of both the classes.

Polymorphism

Polymorphism means the ability to take more than one form. An operation may
exhibit different behaviours in different instances. The behaviour depends on the data
types used in the operation. Polymorphism is extensively used in implementing
Inheritance.[1] The biggest advantage of polymorphism is creation of reusable code
by programmers, classes once written, tested and implemented can be easily reused
without caring about what’s written in the cases.

Student

Full time Student Part time Student

Figure.1

In above fig.1 whatever code is written for student , can be used by full time student
or part time student and if the West London College in given scenario need
another student subclass. For eg.
Student WLC = new student ( );
Student WLC = new Full time Student ( );
Student WLC = new Part time Student ( );
Student WLC = new ……….. Student ( );

7
Advantages of Object-Oriented Programming
• Analysis and Design Made Easier
• Code Reuse
• Ease of Maintenance and Enhancement
• Iterations Fewer and Shorter
• Software reuse is enhanced.
• Software maintenance cost can be reduced.
• Data access is restricted providing better data security.
• Software is easily developed for complex problems.
• Software may be developed meeting the requirements on time, on the
estimated budget.
• Class hierarchies are helpful in the design process allowing increased
extensibility.
• Modularity is achieved.
• Data abstraction is possible.

Limitations of Object-Oriented Programming


• OOP is a high level concepts so takes more time to execute as many routines
run behind at the time of execution.
• Offers less number of functions as compared to low level programming which
interacts directly with hardware.
• Increased burden on part of OOP developer.
• Solving a problem using OOP approach consumes more time than the time
taken by Structured programming approach.

Conclusion:

There are advantages as well as disadvantages to using either structured programming


languages or object-oriented languages when developing an application.

In comparison, object-oriented languages often contain a set of reusable modular


components, which can be called to execute at various points throughout the program,
without rewriting them. The object-oriented programming languages is modular so
it’s possible to use reusable piece of code like class and a function. These can be use
multiple times throughout a programme without rewrite them which can save
developer time and efforts but in structure language code is not split up in to reusable

8
so the code is written and executed sequentially which could have cause redundant
code and may take longer time to develop a programme. Normally we can compare
two programming language as follows.

Structured Programming Language Object Oriented Programming Language

1) Data and Functions don’t tide 1) Functions and data are tide together.
with each other. 2) Programs are divided into entity
2) Large programs are divided into called Objects.
smaller self contained program 3) Data is hidden and can’t be accessed
segment known as functions by the external world
3) Data moves openly around the 4) Functions are not dependent so
system from function to function. reusability is possible
4) Functions are dependent so 5) Focus is given to the data rather than
reusability is not possible procedure.
5) Stress is on the algorithms used to 6) Data is compartmentalized into
solve the problem. Data takes the capsules or objects.
back seat.
7) Decides the classes and objects
6) Algorithm for solving the problem required and provides full set of
is compartmentalized into operations for each class.
modules or functions.
8) It is centered on the concepts of
7) Uses the best algorithm from objects, data abstraction,
among the different procedures encapsulation, inheritance and
available. polymorphism.
8) It has reduced data security and
data integrity, as they are globally
accessible to all the functions.

Data security is more in object oriented algorithm due to private data type as compare
to procedure programming approach. Structured programming language is a simply a
collection of functions but do not have more security. In object oriented programming
there is more secure through using exception handling, encapsulation
and data hiding using its access specifies. Considering this above mention points OOP
is recommended to use to develop a programme for the West London College.

9
CRC Design Method

Student

Student-ID Payment
Name Course
Date of Birth Lecture
Address
Contact No
E-mail ID
Enrolled Course Detail
Payment History
Allocated Tutor Detail

Add Student
Delete Student
Edit Student
Search Student
Display Student Info
Print Student Info

Course

Course-ID Module
Start Date
End Date
Has Module Details
Types of Course
Cost of Course
Days Delivered

Edit Course
Add Course
Delete course
Search Course
View Course
Print Course

10
Lecturer

Lecturer_ID Module
Name Student
DOB
Address
Contact No
E-mail ID
Qualification
Visa Status
Assigned Course
Assigned Student

Add Lecturer Info


Delete Lecturer Info
Edit Lecturer Info
Search Lecturer Info
Display Lecturer Info
Print Lecturer Info

Module

Module Code Lecturer


Name
Description
Assigned Lecturer

Add Module
Delete Module
Edit module
Search Module
Display Module Info
Print module Info

11
Payment

Amount Paid Student


Due Amount
Mode of Payment
Date of Payment
Paid By

Add New Payment


Edit Payment Info
Display Payment Info
Print Payment Info

12
0...M 0...1 Lecturer
Student Class Diagram
Student-ID Lecturer_ID

Name Name

Date of Birth DOB


Course
Address Address
Course-ID
Enrolled Course Detail Contact No
Start Date
Payment History E-mail ID
End Date
Allocated Tutor Detail Qualification
Has Module Details
Add Student
0...M 1...1M Visa Status
Types of Course
Delete Student Assigned Course
Cost of Course
Edit Student Assigned Student
Days Delivered
Search Student Add Lecturer Info
Edit Course
Display Student Info 1...1 Delete Lecturer Info
Add Course
Print Student Info Edit Lecturer Info
Delete course
Search Lecturer Info
Search Course
Display Lecturer Info
View Course
Full Time Student Part Time Student Print Lecturer Info
Print Course
Student-ID Student-ID 1...M
1...M
Name Name 1...M
Date of Birth Date of Birth Module
Payment
Address Address Module Code
Amount Paid
Enrolled Course Detail Enrolled Course Detail Name
Due Amount 1...M
Payment History Payment History Description
Mode of Payment 1...M
Allocated Tutor Detail Allocated Tutor Detail Assigned Lecturer
Date of Payment
Add Student Add Student Add Module
Paid By
Delete Student Delete Student Delete Module
Add New Payment
Edit Student Edit Student Edit module
Edit Payment Info
Search Student Search Student Search Module
Display Payment Info
Display Student Info Display Student Info Display Module Info
13
Print Payment Info
Print Student Info Print Student Info Print module Info
HND (HIGHER NATIONAL DIPLOMA)

Object Oriented Programming


Assignment 2

Rajendra Paudel
Queensland College
Dec 2010

14
CRC using Java Structure

Student Class:

Class Student {
int Student_ID [ ] = new int [5];
String Name [ ] = new String [5];
int DOB [ ] = new int [5];
String Address [ ] = new String [5];
int Contact No [ ] = new int [5];
String enrolled course detail [ ] = new String [5];
String payment history [ ] = new String [5];
String allocated tutor detail [ ] = new String [5];

void add Student ( );


void delete Student ( );
void edit Student ( );
void search Student ( );
void display Student Info( );
void print student Info( );

Lecturer Class:

Class Lecturer {
int Lecturer_ID [ ] = new int [5];
String Name [ ] = new String [5];
int DOB [ ] = new int [5];
String Address [ ] = new String [5];
int Contact No [ ] = new int [5];
String E-mail ID [ ] = new String [5];
String Qualification [ ] = new String [5];
String Visa Status [ ] = new String [5];
String Assigned Course [ ] = new String [5];
String Assigned Student [ ] = new String [5];

15
void Add Lecturer Info ( );
void Delete Lecturer Info ( );
void Edit Lecturer Info ( );
void Search Lecturer Info ( );
void Display Lecturer Info ( );
void Print Lecturer Info ( );

Course Class:

Class Course {
int Course-ID [ ] = new int [5];
String Start Date [ ] = new String [5];
String End Date [ ] = new String [5];
String Has Module Details [ ] = new String [5];
String Types of Course [ ] = new String [5];
int Cost of Course [ ] = new int [5];
int Days Delivered [ ] = new int [5];

void Edit Course ( );


void Add Course ( );
void Delete course ( );
void Search Course ( );
void View Course ( );
void Print Course ( );
}

Module Class

Class Module {
String Module Code [ ] = new String [5];
String Name [ ] = new String [5];
String Description [ ] = new String [5];
String Assigned Lecturer [ ] = new String [5];

16
void Add Module ( );
void Delete Module ( );
void Edit module ( );
void Search Module ( );
void Display Module Info ( );
void Print module Info ( );

Payment Class:

Class Payment {
int Amount Paid [ ] = new int [5];
int Due Amount [ ] = new int [5];
String Mode of Payment [ ] = new String [5];
int Date of Payment [ ] = new int [5];
String Paid By [ ] = new String [5];

void Add New Payment ( );


void Edit Payment Info ( );
void Display Payment Info ( );
void Print Payment Info ( );
}

17
Requirement for JAVA

Java is a computer programming language expressly designed for use in the


distributed environment of the Internet. Java can be used to create complete
applications that may run on a single computer or be distributed among servers and
clients in a network. It can also be used to build a small application module or applet
for use as part of a Web page. To run the Java user need JDK and JRC.

JDK

A software development package that implements the basic set of tools needed to
write, test and debug Java applications and applets. Typically, each JDK contains one
(or more) JRE's along with the various development tools like the Java source
compilers, bundling and deployment tools, debuggers, development libraries, etc.

JRC

The "JRE" is the Java Runtime Environment. JRE is an implementation of the Java
Virtual Machine which actually executes Java Programs.

Hardware and Software requirement

Intel and 100% compatible processors are supported for java installation. A Pentium
166MHz or faster processor with at least 64MB of physical RAM is recommended. It
will also need a minimum of 98MB of free disk space.

18
Windows System Requirements [2]

Windows-32 Bit
Platform Version Memory Browser Diskspace
Chrome 4.0, IE 8,
Windows 7 128mb Firefox 2, Firefox 3.0.x,
Firefox 3.5.x, or Firefox 3.6
Chrome 4.0, IE 7 or IE 8
Windows Vista 128mb Firefox 2, Firefox 3.0.x,
Firefox 3.5.x, or Firefox 3.6
IE 7 or IE 8, Firefox 2,
Windows
128mb Firefox 3.0.x, Firefox 3.5.x,
Windows Server 2008
or Firefox 3.6
x86 Chrome 4.0, IE 6 SP1, IE 7 98MB
or IE 8, Firefox 2, Firefox
Windows XP 64mb
3.0.x, Firefox 3.5.x, or
Firefox 3.6
IE 5.5 or IE 6, Mozilla 1.4,
Windows 2000 64mb
Mozilla 1.7, Firefox 2
IE 7 or IE 8, Firefox 2,
Windows
128mb Firefox 3.0.x, Firefox 3.5.x,
Server 2003
or Firefox 3.6
Chrome 4.0, IE 8
Windows 7 128mb Firefox 2, Firefox 3.0.x,
Firefox 3.5.x, or Firefox 3.6
Chrome 4.0, IE 7 or IE 8
Windows Vista 128mb Firefox 2, Firefox 3.0.x,
Firefox 3.5.x, or Firefox 3.6
IE 7 or IE 8, Firefox 2,
Windows
128mb Firefox 3.0.x, Firefox 3.5.x,
Windows Server 2008
or Firefox 3.6
x64 Chrome 4.0, IE 6 SP1, IE 7 98MB
32-bit mode or IE 8, Firefox 2, Firefox
Windows XP 64mb
3.0.x, Firefox 3.5.x, or
Firefox 3.6
IE 5.5 or IE 6, Mozilla 1.4,
Windows 2000 64mb
Mozilla 1.7, Firefox 2
IE 7 or IE 8, Firefox 2,
Windows
128mb Firefox 3.0.x, Firefox 3.5.x,
Server 2003
or Firefox 3.6

19
Windows (64-bit)
Platform Version Memory Browsers Disk
Space
Windows 7 64-bit OS, 32-bit Browsers:
Chrome 4.0, Firefox 2, Firefox
3.0.x, Firefox 3.5.x, or Firefox
3.6
64-bit OS, 64-bit Browsers:
IE 8
Windows 64-bit OS, 32-bit Browsers:
Server 2008 Firefox 2, Firefox 3.0.x,
Windows Windows 128 MB Firefox 3.5.x, or Firefox 3.6 98 MB
x64 Vista 64-bit OS, 64-bit Browsers:
64-bit mode IE 8
Windows XP 64-bit OS, 32-bit Browsers:
Chrome 4.0, IE 6 SP1, IE 7, or
IE 8, Mozilla 1.4.X or 1.7,
Netscape 7.x, Firefox 1.06 -
3.0.x, Firefox 3.5.x, or Firefox
3.6

64-bit OS, 64-bit Browsers:


IE 7 or IE 8
Windows 64-bit OS, 32-bit Browsers:
2003, Standard IE 6 SP1, IE 7, or IE 8,
Edition (R2, Mozilla 1.4.X or 1.7, Netscape
SP1, SP2) 7.x, Firefox 1.06 - 3.0.x,
Firefox 3.5.x, or Firefox 3.6

64-bit OS, 64-bit Browsers:


IE 7 or IE 8

Linux System Requirements

Linux 32-bit
Platform Versions Memory Browsers Disk Space
Oracle Enterprise Firefox 3.0.x,
Linux 5.5, 5.4 Firefox 3.5.x,
or Firefox 3.6
Red Hat Enterprise Firefox 3.0.x, 58 MB
Linux Linux 5.3, 5.4, 5.5 64mb Firefox 3.5.x,
x86 or Firefox 3.6
SUSE 10 Firefox 2.0.x
SLES 11 Firefox 3.0.6,
Firefox 3.0.8

20
Linux 64-bit
Platform Versions Memory Browsers Disk Space
Oracle 64-bit OS, 32-bit
Enterprise Browsers: Firefox
Linux 5.5, 5.4 3.0.x, Firefox 3.5.x,
or Firefox 3.6
Red Hat 64-bit OS, 32-bit
Linux Enterprise 64mb Browsers: 58 MB
x64 Linux 5.3, 5.4, Firefox 3.0.x,
64-bit mode 5.5 Firefox 3.5.x,
or Firefox 3.6
Red Hat 64-bit OS, 32-bit
Enterprise Browsers:
Linux 5.0 (5.1, Firefox 3.0.x,
5.2) Firefox 3.0.x,
SUSE 8.2, 64-bit OS, 32-bit
9, 9.1, 9.2 Browsers:
Mozilla 1.4
SLES 11 64-bit OS, 32-bit
Browsers:
Firefox 3.0.6 or
3.0.8
SLES 10 64-bit OS, 32-bit
Browsers:
Firefox 2.0.x

21
Role of Class Library in Java
Object oriented programming languages define all of their functionality in terms of
objects. All objects of the same type make up a class of objects which have common
functionality and it is coded into the program as a class which can called as a
collection of prewritten, ready-made software routines that act as templates for
programmers to use in writing programs.

The greatest benefits are primarily for application extensibility code re-usability and
program stability. Access to and use of a class library greatly simplifies the job of the
programmer since standard, pretested code is available that the programmer doesn't
have to write. The class libraries provide an abstract interface to tasks that would
normally depend heavily on the hardware and operating system.

Why use Class Library?

• By reusing functions from Java's huge class library, software can be


implemented faster and with fewer errors.
• The abstraction provided by the Java class library is cleaner, which makes
them easier to understand and use.
• Standard, pretested code is available that the programmer doesn't have to write
any code.
• Graphic
• Error maintain

Abstract Windowing Toolkit (AWT)

Window Toolkit (AWT) is a set of application program interfaces ( API s) used by


Java programmers to create graphical user interface ( GUI ) objects, such as buttons,
scroll bars, and windows for applets and standalone applications.

Java Applet

Java applet gives the interactive web development. An applet is a special kind of Java
program that a browser enabled with Java technology can download from the internet
and run. An applet is typically embedded inside a web page and runs in the context of
a browser. An applet must be a subclass of the java.applet.Applet class.

22
Sample Programme

import java.awt.*;
import java.applet.*;

public class GuiExample extends Applet {

Button okButton;

TextField nameField;

CheckboxGroup radioGroup;

Checkbox radio1;
Checkbox radio2;

Checkbox option;

public void init()


{
SetLayout(null);

okButton = new Button("First button");

nameField = new TextField("First TextField",100);

radioGroup = new CheckboxGroup();

radio1 = new Checkbox("Radio1", radioGroup,false);

radio2 = new Checkbox("Radio2", radioGroup,true);

option = new Checkbox("Option",false);

okButton.setBounds(20,20,100,30);

23
nameField.setBounds(20,70,100,40);
radio1.setBounds(20,120,100,30);
radio2.setBounds(140,120,100,30);
option.setBounds(20,170,100,30);

add(okButton);
add(nameField);
add(radio1);
add(radio2);
add(option);
}

24
References

http://wiki.tcl.tk/13398 [Accessed 15 Nov 2010]

http://www.java.com/en/download/help/sysreq.xml [Accessed 26 Nov 2010]

25

You might also like