hnd-oop assignment

35
HND (HIGHER NATIONAL DIPLOMA) Object Oriented Programming Assignment 1 1

Upload: sandhya-paudel

Post on 14-Oct-2014

272 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: HND-OOP assignment

HND (HIGHER NATIONAL DIPLOMA)

Object Oriented ProgrammingAssignment 1

Rajendra PaudelQueensland College

Dec 2010

1

Page 2: HND-OOP assignment

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

Page 3: HND-OOP assignment

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

Page 4: HND-OOP assignment

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

Page 5: HND-OOP assignment

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

Page 6: HND-OOP assignment

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

Page 7: HND-OOP assignment

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.

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

Student

Full time Student Part time Student

Page 8: HND-OOP assignment

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

Page 9: HND-OOP assignment

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 with each other.

2) Large programs are divided into smaller self contained program segment known as functions

3) Data moves openly around the system from function to function.

4) Functions are dependent so reusability is not possible

5) Stress is on the algorithms used to solve the problem. Data takes the back seat.

6) Algorithm for solving the problem is compartmentalized into modules or functions.

7) Uses the best algorithm from among the different procedures available.

8) It has reduced data security and data integrity, as they are globally accessible to all the functions.

1) Functions and data are tide together.

2) Programs are divided into entity called Objects.

3) Data is hidden and can’t be accessed by the external world

4) Functions are not dependent so reusability is possible

5) Focus is given to the data rather than procedure.

6) Data is compartmentalized into capsules or objects.

7) Decides the classes and objects required and provides full set of operations for each class.

8) It is centered on the concepts of objects, data abstraction, encapsulation, inheritance and polymorphism.

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

Page 10: HND-OOP assignment

CRC Design Method

Student

Student-ID

Name

Date of Birth

Address

Contact No

E-mail ID

Enrolled Course Detail

Payment History

Allocated Tutor Detail

Payment

Course

Lecture

Add Student

Delete Student

Edit Student

Search Student

Display Student Info

Print Student Info

Course

Course-ID

Start Date

End Date

Has Module Details

Types of Course

Cost of Course

Days Delivered

Module

Edit Course

Add Course

Delete course

Search Course

View Course

Print Course

10

Page 11: HND-OOP assignment

Lecturer

Lecturer_ID

Name

DOB

Address

Contact No

E-mail ID

Qualification

Visa Status

Assigned Course

Assigned Student

Module

Student

Add Lecturer Info

Delete Lecturer Info

Edit Lecturer Info

Search Lecturer Info

Display Lecturer Info

Print Lecturer Info

Module

Module Code

Name

Description

Assigned Lecturer

Lecturer

Add Module

Delete Module

Edit module

Search Module

Display Module Info

Print module Info

11

Page 12: HND-OOP assignment

Payment

Amount Paid

Due Amount

Mode of Payment

Date of Payment

Paid By

Student

Add New Payment

Edit Payment Info

Display Payment Info

Print Payment Info

12

Page 13: HND-OOP assignment

Class Diagram Lecturer

Lecturer_ID

Name

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

Student

Student-ID

Name

Date of Birth

Address

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

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

Module

Module Code

Name

Description

Assigned Lecturer

Add Module

Delete Module

Edit module

Search Module

Display Module Info

Print module Info

Payment

Amount Paid

Due Amount

Mode of Payment

Date of Payment

Paid By

Add New Payment

Edit Payment Info

Display Payment Info

Print Payment Info

Full Time Student

Student-ID

Name

Date of Birth

Address

Enrolled Course Detail

Payment History

Allocated Tutor Detail

Add Student

Delete Student

Edit Student

Search Student

Display Student Info

Print Student Info

Part Time Student

Student-ID

Name

Date of Birth

Address

Enrolled Course Detail

Payment History

Allocated Tutor Detail

Add Student

Delete Student

Edit Student

Search Student

Display Student Info

Print Student Info

0...M 0...1

1...M

1...M

1...M

1...M

1...10...M

1...1

1...M

13

Page 14: HND-OOP assignment

HND (HIGHER NATIONAL DIPLOMA)

Object Oriented ProgrammingAssignment 2

Rajendra PaudelQueensland College

Dec 2010

14

Page 15: HND-OOP assignment

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

Page 16: HND-OOP assignment

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

Page 17: HND-OOP assignment

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

Page 18: HND-OOP assignment

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

Page 19: HND-OOP assignment

Windows System Requirements [2]

Windows-32 BitPlatform Version Memory Browser Diskspace

Windows x86

Windows 7 128mbChrome 4.0, IE 8,Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

98MB

Windows Vista 128mbChrome 4.0, IE 7 or IE 8Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windows Server 2008

128mbIE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windows XP 64mb

Chrome 4.0, IE 6 SP1, IE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windows 2000 64mbIE 5.5 or IE 6, Mozilla 1.4, Mozilla 1.7, Firefox 2

Windows Server 2003

128mbIE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windowsx64 32-bit mode

Windows 7 128mbChrome 4.0, IE 8Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

98MB

Windows Vista 128mbChrome 4.0, IE 7 or IE 8Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windows Server 2008

128mbIE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

Windows XP 64mb

Chrome 4.0, IE 6 SP1, IE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.6

Windows 2000 64mbIE 5.5 or IE 6, Mozilla 1.4, Mozilla 1.7, Firefox 2

Windows Server 2003

128mbIE 7 or IE 8, Firefox 2, Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

19

Page 20: HND-OOP assignment

Windows (64-bit)Platform Version Memory Browsers Disk

Space

Windowsx64 64-bit mode

Windows 7

128 MB

64-bit OS, 32-bit Browsers: Chrome 4.0, Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.664-bit OS, 64-bit Browsers: IE 8

98 MB

Windows Server 2008

64-bit OS, 32-bit Browsers: Firefox 2, Firefox 3.0.x, Firefox 3.5.x, or Firefox 3.664-bit OS, 64-bit Browsers: IE 8

Windows Vista

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.664-bit OS, 64-bit Browsers: IE 7 or IE 8

Windows 2003, Standard Edition (R2, SP1, SP2)

64-bit OS, 32-bit Browsers: 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.664-bit OS, 64-bit Browsers: IE 7 or IE 8

Linux System Requirements

Linux 32-bitPlatform Versions Memory Browsers Disk Space

Linux x86

Oracle Enterprise Linux 5.5, 5.4

64mb

Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

58 MBRed Hat Enterprise Linux 5.3, 5.4, 5.5

Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

SUSE 10 Firefox 2.0.xSLES 11 Firefox 3.0.6,

Firefox 3.0.8

20

Page 21: HND-OOP assignment

Linux 64-bitPlatform Versions Memory Browsers Disk Space

Linuxx64 64-bit mode

Oracle Enterprise Linux 5.5, 5.4

64mb

64-bit OS, 32-bit Browsers: Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

58 MBRed Hat Enterprise Linux 5.3, 5.4, 5.5

64-bit OS, 32-bit Browsers: Firefox 3.0.x, Firefox 3.5.x,or Firefox 3.6

Red Hat Enterprise Linux 5.0 (5.1, 5.2)

64-bit OS, 32-bit Browsers: Firefox 3.0.x,Firefox 3.0.x,

SUSE 8.2, 9, 9.1, 9.2

64-bit OS, 32-bit 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

Page 22: HND-OOP assignment

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

Page 23: HND-OOP assignment

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);

nameField.setBounds(20,70,100,40);

23

Page 24: HND-OOP assignment

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

Page 25: HND-OOP assignment

References

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

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

25