46
5 th Semester OOAD Lab. CS&E. 1 Problem 2: GRID LINES Specification: Grid with two set of horizontal lines (Rumbhaugh approach) Write a program to create a window and draw horizontal and vertical lines to form a grid. High-Level Design: Define a sub class of jframe class and draw horizontal parallel lines and vertical parallel lines to form the grid. Create an object of this class and display it. Detail Level Design: User interface specification: The window contains a grid of horizontal and vertical lines. For this we define a GUI class called Ruled derived from frame class of javax.swing library. Name of the GUI component: ruled class hierarchy :subclass of JFrame class of Javax.swing library. Title of the window : none Background color: none Background design: none Content of the window Parallel horizontal and vertical line are drawn inside the window to form a grid. Control classes: We define a class called window handler to handle the window. This is derived from the window adapter class. Print() method: using this method we draw the grid. Ruled class Javax.swing.Jfr ame Super class Subclass JFrame Ruled Window Handler Window Adapter

OOAD

Embed Size (px)

Citation preview

Page 1: OOAD

5th

Semester OOAD Lab.

CS&E. 1

Problem 2: GRID LINES

Specification: Grid with two set of horizontal lines (Rumbhaugh approach)

Write a program to create a window and draw horizontal and vertical lines to form a grid.

High-Level Design:

Define a sub class of jframe class and draw horizontal parallel lines and vertical parallel lines to

form the grid. Create an object of this class and display it.

Detail Level Design:

User interface specification:

The window contains a grid of horizontal and vertical lines.

For this we define a GUI class called Ruled derived from frame class of javax.swing library.

Name of the GUI component: ruled class hierarchy :subclass of JFrame class of

Javax.swing library.

Title of the window : none

Background color: none

Background design: none

Content of the window

Parallel horizontal and vertical line are drawn inside the window to form a grid.

Control classes:

We define a class called window handler to handle the window. This is derived from the

window adapter class.

Print() method: using this method we draw the grid.

Ruled class

Javax.swing.Jfr

ame Super class

Subclass

JFrame

Ruled

Window

Handler

Window

Adapter

Page 2: OOAD

5th

Semester OOAD Lab.

CS&E. 2

Use case Diagram:

Class Diagram:

Grid

Set Dimension

Create & Handle Window

Draw Line

Programmer

<<extend>>

<<derive>>

<<derive>>

Horizontal

Horizontal()

paint()

main()

jblnit()

(from Logical View)

Sequence Diagram:

Horizontal java.awt.* javax.swing.JFr

ame

java.FileInputSt

ream

java.awt.Dimen

sion

1: setBackground()

2: setForeground()

3: drawline()

4: setTitle()

5: setBounds()

6: setContentPane()

7: setSize()

8: show()

Page 3: OOAD

5th

Semester OOAD Lab.

CS&E. 3

Source Code:

import java.awt.*;

import java.awt.event.*;

import java.awt.Dimension;

import javax.swing.*;

import javax.swing.JFrame;

public class Ruled extends JFrame

{

public Ruled()

{

try

{

jbInit();

}

catch(Exception e)

{

e.printStackTrace();

}

}

public void paint(Graphics g)

{

for(int i=0;i<400;i+=25)

{

g.drawLine(0,i,400,i);

g.drawLine(i,0,i,400);

}

}

public static void main(String args[])

{

Ruled r =new Ruled();

r.setBounds(1,1,400,400);

r.show();

}

private void jbInit() throws Exception

{

this.getContentPane().setLayout(null);

this.setSize(new Dimension(400,300));

}

}

Page 4: OOAD

5th

Semester OOAD Lab.

CS&E. 4

Problem 3: GRID WITH TWO SETS OF DIAGONAL LINES

a) Identify the various use cases and actors involved and represent the user view of

the system.

b) Identify the various classes and attributes and bring out a class diagram, and a

sequence diagram.

Write a program to create a window and draw two sets of diagonal parallel lines crossing each

other. Device the following and then implement.

a) High level design

b) Detail level design

c) User interface specification

Use case Diagram:

Grid

Set Dimension

Create & Handle Window

Draw Line

Programmer

<<extend>>

<<derive>>

<<derive>>

Class Diagram:

Crossed

Crossed()

paint()

main()

jbInit()

Page 5: OOAD

5th

Semester OOAD Lab.

CS&E. 5

Sequence Diagram:

Crossed java.awt.* javax.swing.JFr

ame

java.FileInputSt

ream

java.awt.Dimen

sion

1: setBackground()

2: setForeground()

3: drawline()

4: setTitle()

5: setBounds()

6: setContentPane()

7: setSize()

8: show()

Page 6: OOAD

5th

Semester OOAD Lab.

CS&E. 6

Source Code: import java.awt.*;

import java.awt.event.*;

import java.awt.Dimension;

import javax.swing.*;

import javax.swing.JFrame;

import javax.swing.*;

public class Crossed extends JFrame

{

public Crossed()

{

try

{

jbInit();

setBackground(new Color(110,55,75));

setForeground(new Color(0,255,200));

}

catch(Exception e) {

e.printStackTrace();

}

}

public void paint(Graphics g)

{

for(int i=0;i<400;i+=25)

{

g.drawLine(0,i,i,0);

g.drawLine(400,i,i,400);

}

for(int j=0;j<400;j+=25)

{

g.drawLine(j,0,400,400-j);

g.drawLine(0,j,400-j,400);

}

}

public static void main(String args[])

{

Crossed cw = new Crossed();

cw.setTitle("Crossed");

cw.setBounds(1,1,400,400);

cw.show();

}

private void jbInit() throws Exception

{

this.getContentPane().setLayout(null);

this.setSize(new Dimension(400,300));

}

}

Page 7: OOAD

5th

Semester OOAD Lab.

CS&E. 7

Problem 4: OOA AND OOD USING UML-I

In the employee referral process, the HR head of the region where a vacancy exists informs

employees of the region and other regional HR heads. The other regional HR head inform

employees by putting up a notice informing them about the vacancy. The employees send on

their recommendations to the regional HR head of the region where a vacancy exists. The

regional HR head then matches the skills of these candidates with the skills required for vacant

position and short list them. An interview schedule is drawn up and the listed candidates are

informed, based on the interview proceedings, interview details are updated and all selected

candidates are given offer letter. The candidates inform the HR either by accepting or declining

the offer letter. When a candidate referred by an employee joins the organization, the employee

who has referred the candidate is paid a bonus.

a) Identify the various use cases and actors involved and represent the user view of the

system.

b) Identify the various classes and attribute and bring out a class diagram, and a sequence

diagram.

Use Case Diagram:

Notice

Offerletter

Interview

Shortlist

CandidateRecommends

Vacancy

EmployeeHR Head

Bonus

<<extend>>

Page 8: OOAD

5th

Semester OOAD Lab.

CS&E. 8

Use Cases:

Vacancy: Informs about the vacancy to the different HR Heads and the Employees.

Notice: It is same as that of the vacancy usecase, but it is displayed on the notice board.

Recommends: The employees or the HR Head can recommend the candidates.

Shortlist: The HR Head shortlists the candidates.

Interview: The interview process is carried out to the shortlisted candidates.

Offer Letter: The offer letters are offered to the selected candidates.

Actors:

HR Head

Employee

Candidate

Class Diagram:

Page 9: OOAD

5th

Semester OOAD Lab.

CS&E. 9

Classes:

Company: This class contains the details of the company.

HR Head: This class maintains the details of the HR Head and provides the operations such as

Identify vacancy, inform employees, Matching the skills, short listing the candidates, conducting

the interview, selecting the candidates and offering the letters to the selected candidates.

Vacancy: Vacancy class contains the details of the vacancy such as its location, type of the post,

Salary, Experience needed.

Employee: Employee class contains the details of the employee. It performs the operations such

As sending the recommendations to the HR heads and accepting the bonus.

Candidate: This class contains the details of the candidate such as name, location, experience and

Performs the operations like sending the resume, attending the interview and accepting/rejecting

The offer letter.

Sequence Diagram:

: HR Head : Vacancy : Employee : Candidate

1: Identify()

2: Inform()

3: Inform()

4: Send Recomendation()

5: Match Skills & Shortlist()

6: Conduct Interview()

7: Select Candidates( )

8: Send Offer Letter()

9: Accept/Reject Offer Letter()

10: Pay bonus()

Page 10: OOAD

5th

Semester OOAD Lab.

CS&E. 10

Problem 5: OOA AND OOD USING UML-II

UML class representation: design and implement a student class with the following

attributes:

i) Reg No.

ii) Name of the student

iii) Marks in subject I

iv) Marks in subject II

v) Total marks.

The total of the 3 subjects must be calculated only when the student passes in all the subjects.

The pass marks for each of the subject is 50. if a candidate falls in any one of the subjects his

total marks must be declared as 0. Using these conditions write a constructor for the class.

Write a method display student () to display the details of student object. In the main method

create an array of 3 student objects and display the object details.

a) Identify the various use cases and actors involved and represent the user view of the

system.

b) Identify the various classes and attribute and bring out a class diagram and a sequence

diagram.

USE-CASE DIAGRAM

Enter student information

Calculate the marks

Display results

User

Page 11: OOAD

5th

Semester OOAD Lab.

CS&E. 11

User: User enters the marks, calculate the marks and display the result.

Use case-1

Enter student details: This is the use case where in user is going to enter the all information

(name and marks) regarding the student.

Use case-2

Calculate the marks: This is the use case, which calculates the marks entered by the user.

Use case-3

Display the result: This is the use case, which displays the result.

CLASS DIAGRAM

Student

name : String

Reg.No. : String

Marks1 : Integer

Marks2 : Integer

Marks3 : Integer

Total Marks : Integer

Enter the marks()

Calculate the marks()

Display the result()

Class Student: This is a student class, which has the following attributes and methods.

Attributes: Name, RegNo, Marks1, Marks2, Marks3, and Total Marks.

Methods: Enter the marks (), Calculate the marks () and Display the result ().

Page 12: OOAD

5th

Semester OOAD Lab.

CS&E. 12

SEQUENCE DIAGRAM

User

Enter the marks( )

Calculate marks( )

Display marks( )

The above diagram shows the sequence in which the user is going to enter the marks, calculate the marks

and display the result.

Page 13: OOAD

5th

Semester OOAD Lab.

CS&E. 13

Java code.

import java.io.*;

import java.lang.*;

public class Student_5

{

String name;

int sub1,sub2,sub3;

int total;

Student_5()

{

try

{

DataInputStream d=new DataInputStream(System.in);

name=d.readLine();

sub1=Integer.parseInt(d.readLine());

sub2=Integer.parseInt(d.readLine());

sub3=Integer.parseInt(d.readLine());

}

catch(IOException e)

{

System.out.println(e.getMessage());

}

if (sub1 < 50 || sub2<50 || sub3<50)

total = 0;

else

total = sub1+sub2+sub3;

}

public void displayStudent()

{

System.out.println("NAME : " + name);

System.out.println("Total : "+total);

}

public static void main(String args[])

{

Student_5[] st = new Student_5[3];

System.out.println("Enter name and marks of student1");

st[0] = new Student_5();

System.out.println("Enter name and marks of student2");

st[1] = new Student_5();

System.out.println("Enter name and marks of student3");

st[2] = new Student_5();

st[0].displayStudent();

st[1].displayStudent();

st[2].displayStudent();

}

}

Page 14: OOAD

5th

Semester OOAD Lab.

CS&E. 14

Problem 6: OOA AND OOD USING UML - III

Consider the student class defined in the problem 2. Assume that the student studies six

subjects. Each subject has a title, passing minimum marks, and maximum marks. Design the

class representation using UML notations and write a java program to define student class

including the subject as attribute. Design specifications: A student studies 6 subjects. Each

subject has a subject code, title, passing minimum marks, maximum marks. The following table

shows the sample data:

Subject code Title Passing Min. Max. Marks

CS401 Java Program 50 100

CS406 ASW Lab 18 50

-------- --------- ----------- ---------

--------- ---------- ----------- ---------

-------- ---------- --------- ----------

You must first define a class called subject. For every student there is an array of 6 subjects. Since

every student in this example will study only the same subjects, we declare it as static. The student class

will have the following attribute: Reg. No., name, subject array, marks array, result array, and total.

� Identify the various use cases and actors involved and represent the user view of the

system.

� Identify the various classes and attributes and bring out a class diagram, and a sequence

diagram.

Page 15: OOAD

5th

Semester OOAD Lab.

CS&E. 15

Activity Diagram:

Calculate Result

Display Result

Enter Student Marks

USER

Actor:

User: He/She will be the initiator of use cases.

Use Cases:

Enter Student Marks: This use case will be used to enter the marks of the student obtained in

the six subjects.

Calculate Result: This use case will be used to calculate the marks in individual subjects as well

as Total marks of the Students.

Display Result: This use case will be used to display the result of each Student.

Page 16: OOAD

5th

Semester OOAD Lab.

CS&E. 16

Class Diagram:

Student

reg_no : String

student_name : String

<<array>> subject : Object

<<array>> marks : Integer

<<array>> result : String

total_marks : integer

calculate_result()

calculate_total()

<<constructor>> Student()

Display()

Enter_student_marks()

Subject

<<static>> subjectCode : String

<<static>> subject_title : String

<<static>> minimum_marks : integer

<<static>> maximum_marks : integer

<<constructor>> Subject()

<<static>>

*1..*1..* *

Classes:

Student:

This class will initialize the students with marks obtained in six subjects with their details

such as Register No and Name of the Student.

Its main operations are to calculate the result in each subject and to calculate the total

marks obtained by each student.

Then it will show the result to the user in specified format.

Subject:

This class will initialize the subject’s details such as subject code; subject name, minimum

marks and maximum marks to be scored in each subject.

Page 17: OOAD

5th

Semester OOAD Lab.

CS&E. 17

Sequence Diagram:

Student :

Student

Subject :

Subject

1: Initialise Student { regno, name, marks of six subjects }

2: Enter Subject { code,name,min,max }

3: Return subject details

4: Calculate the Result

5: Calculate the Total

6: Display the Results

Page 18: OOAD

5th

Semester OOAD Lab.

CS&E. 18

Java Program:

class Subject

{

String code;

String title;

int passingmin;

int max;

Subject(String cd,String tit,int min,int total)

{

code = cd;

title = tit;

passingmin=min;

max=total;

}

}

public class Student

{

String regNo;

String name;

static Subject subject[];

int mark[];

String result[];

int total;

float average;

int totalMax;

public Student(String r,String n,int m[])

{

regNo = r;

name = n;

mark = new int[6];

for(int j=0;j<6;j++)

{ mark[j] = m[j]; }

result = new String[6];

for(int i=0; i< 6; i++)

{

if(mark[i] >= subject[i].passingmin)

{

result[i]="PASS";

}

else

{

result[i]="FAIL";

}

Page 19: OOAD

5th

Semester OOAD Lab.

CS&E. 19

total+=mark[i];

totalMax+=subject[i].max;

}

average = ((float) total * 100)/(float)totalMax;

}

public void displayStudent() {

System.out.println("\nNAME : " + name);

System.out.println("Reg No. : " + regNo);

System.out.println("\n Code \t Title

\t\t\t\tMark\tMax\tResult");

for(int i=0;i<6; i++)

{

System.out.println(subject[i].code +

"\t"+subject[i].title + "\t\t"+mark[i] +

"\t"+subject[i].max + "\t"+result[i]);

}

System.out.println("\nTotal : "+total);

System.out.println("Average Percentage: "+average);

}

public static void main(String args[])

{

Student.subject= new Subject[6];

Student.subject[0]=new Subject("98CT01","Java

Programming",50,100);

Student.subject[1]=new Subject("98CT02","System Analysis"

,20,50);

Student.subject[2] = new Subject("98CP03","COBOL”,100,200);

Student.subject[3]=new Subject("98CP04","PROJECT",100,200);

Student.subject[4]=new Subject("98CT05","Mini Project",

45,75);

Student.subject[5]=new Subject("98CT06","System Design”,

45,75);

int mk1[]={85,41,125,180,75,60};

int mk2[]={85,45,198,183,74,60};

Student st1,st2;

st1 = new Student("1si02mca1","Shivakumar",mk1);

st2 = new Student("1si02mca2","Rakesh",mk2);

st1.displayStudent();

st2.displayStudent();

}

}

Page 20: OOAD

5th

Semester OOAD Lab.

CS&E. 20

Problem 7: OOA AND OOD USING UML-IV

A class called television has the following attributes: 1) Make 2) Screen size 3) Purchase

date 4) color b&w. Define a class television. Define a method for displaying the attribute value

of a T.V. Represent this Problem specification using UML notations and write a java program

for the same. The television class should be designed with a required attribute. The main method

may be used to print the attributes of television class.

a) Identify various cases and actors involved represent the user view of the system.

b) Identify various cases and attributes and bring out a class diagram, and a sequence

diagram.

Use case Diagram:

Customer

Display the attributes

Television

Insert the attributes

Actors:

1. Customer: Requests & views the attributes of the television.

2. Television: Displays the attributes to the Customer.

Use Cases:

1. Display the attributes: Displays attributes to the customer.

2. Insert the attributes: Accepts the attributes of the television.

Page 21: OOAD

5th

Semester OOAD Lab.

CS&E. 21

Class Diagram:

Television

Make : Integer

ScreenSize : Integer

PurchaseDate : java.sql.Date

color : String

Display()

Television()

Customer

main()1..*1..*1..* 1..*

Classes:

1.Television: Initializes the attributes of television using constructor Television().

Displays the attributes to the Customer using method Display().

2.Customer: Views the attributes of the television.

Sequence Diagram:

Televis ionCus tom er

Reques t for the Details

Display back the Details

Page 22: OOAD

5th

Semester OOAD Lab.

CS&E. 22

Source Code:

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.io.IOException;

import java.util.Date;

class Television

{

private int Make;

private int ScreenSize;

private String Type;

public Customer theCustomer;

Date purchaseDate=new Date();

public Television()

{

try

{

BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));

System.out.println("Enter the Make");

Make=Integer.parseInt(br.readLine());

System.out.println("Enter the ScreenSize");

ScreenSize=Integer.parseInt(br.readLine( ));

System.out.println("Enter the Type");

Type = br.readLine();

}

catch(IOException e){

System.out.println(e.getMessage( ));

}

}

public void Display()

{

System.out.println("Make = " + Make);

System.out.println("ScreenSize = " + ScreenSize);

System.out.println("PurchaseDate = " + purchaseDate);

System.out.println("Type = " + Type);

}

}

Page 23: OOAD

5th

Semester OOAD Lab.

CS&E. 23

public class Customer

{

public static void main(String args[])

{

Television t = new Television();

t.Display();

}

}

Page 24: OOAD

5th

Semester OOAD Lab.

CS&E. 24

Problem 8: OOA AND OOD USING UML V

Bank interest computation

Consider the following Attributes:

P = Principle

R = Rate of Interest

N = Number of years

SI = Simple Interest

A = Amount

Design UML class called Deposit with the above five attributes. In the constructor,

calculate simple interest (SI) and amount. Implement the above specification using java

programming language.

Class Diagram: The constructor initializes the values for principle, rate of interest, and the

no of years. Then calculates the simple interest and the amount. The display function displays the

values of all the attributes of the Deposit class.

Depos it

princ ipl e : f loa t

rate : fl oat

no_of_y ears : i nt

s im ple_i nt : fl oat

amount : float

Depos i t()

d is pl ay ()

Java Code for the above problem

import java.io.*;

import java.util.*;

public class Deposit

{

private float principle;

private float rate;

private int no_of_years;

private float simple_int;

private float amount;

Page 25: OOAD

5th

Semester OOAD Lab.

CS&E. 25

Deposit(int no, float pr, float rt)

{

no_of_years = no;

principle = pr;

rate = rt;

simple_int = (principle*no_of_years*rate)/100;

amount = simple_int + principle;

}

public void display()

{

System.out.println(" Principle =" + principle);

System.out.println(" Rate of Interest =" + rate);

System.out.println(" No of Years ="+ no_of_years);

System.out.println(" Simple Interest ="+ simple_int);

System.out.println(" Amount = " + amount);

}

public static void main( String args[])

{

int no = 0;

float pr = 0, rt = 0;

DataInputStream d = new DataInputStream(System.in);

try

{

System.out.println(" Enter the Principle: ");

pr = Float.parseFloat(d.readLine());

System.out.println(" Enter the Rate of Interest: ");

rt = Float.parseFloat(d.readLine());

System.out.println(" Enter the No of Years: ");

no = Integer.parseInt(d.readLine());

}

catch(Exception e){ }

Deposit di = new Deposit( no, pr, rt);

di.display();

}

}

Page 26: OOAD

5th

Semester OOAD Lab.

CS&E. 26

Problem 9: OOA AND OOD USING RAUMBHAG AND UML VI

In a bank the customer opens an account and in that account he/she deposits money. So

the entities are:

A customer can have several accounts and an account can be spent as a joint account by

several customers. In the customer class, the address of the customer is constructed as an object

of a class called Address. Write the UML class diagram consisting Customer class and Address

class. In the account class, there is an attribute called users. This is an integer attribute. It tells

number of users of the account. If the account is a joint account by 5 persons, the value of

users=5. If it is a single user account, users =1.

Write the UML class diagrams for account.

The Account number is long type. cust() is an array of length=users. If the users=5, cust()

is of the length 5. Another attribute of the Account is an object of Deposit class. Write the UML

class diagram for Deposit.

TEST CASE:

Address:

Customer Account Deposit

Object name User ID FName LName DOB Address Phone no

Object name Street City State Country Pin code

Page 27: OOAD

5th

Semester OOAD Lab.

CS&E. 27

Class Diagram:

Deposit

Principle : Double

No of Years : Integer

Rate Of Interest : Double

Simple Interest : Double

Amount : Double

Calculate_Interest()

Calculate_Amount()

Address

Street : String

City : String

State : String

Country : St ring

PIN : Integer

Get_Address()

Account

Acc NO : Long

Users : Integer

Cust[Users] : Object

Deposit : Object

Open_Account()

Deposit_Money()

Customer

Customer Id : String

First Name : String

Last Name : String

Phone No : Integer

DOB : String

Address : Object

Display_Customer_Info()

Accept_Customer_Info()

Get_Customer_Details()

1..*1..*1..* 1..*

+Has

Classes:

Customer Class: This class is used to maintain the details of customers of a bank. Provides

operations such as accepting customer information and facilitating the other objects to access the

customer details.

Address: Object of this class used in customer as a address storing entity.

Account Class: This class facilitates a customer or customers to open a new account or accounts

and deposit money.

Deposit: This class facilitates to deposit principle amount for number of years at particular rate

of interest that helps in calculating the simple interest and the final amount.

Page 28: OOAD

5th

Semester OOAD Lab.

CS&E. 28

Problem 10: OOA AND OOD USING BOOCH JAND UML-VII

Consider the object College of mini project .For the entire given specifications in the

Problem construct the following UML diagrams.

Specifications:

In the College of computer Science there are computer laboratories and equipments.

Develop a system to create the college as an object and display the contents.

1. Class diagram.

2. Object diagram.

3. Interaction diagrams.

a. Sequence diagram. b. Collaboration diagram.

4. Deployment diagram.

1. Class Diagram:

College class: The College class contains the id, name, and address of the college. It displays the

information about the college, labs, and the equipments in the labs.

Laboratory class: The Laboratory class contains information about the laboratory. It contains

functions for adding and removing equipment, status of laboratory, staff information, etc.

Equipment class: The Equipments class contains information regarding equipment number, total

no of equipments, and equipment details installed in the laboratory. The Equipment class

contains functions for displaying and purchasing of equipments.

In the class diagram given below, the equipment class is a-part-of the laboratory class

that in turn is a-part-of the college class.

Page 29: OOAD

5th

Semester OOAD Lab.

CS&E. 29

Class Diagram

equipments

Equipment No : Integer

Equipment : String

purchaseequipment()

equipinfo()

College

College_id : Integer

College_Name : String

Address : String

displaycollegeinfo()

showlabinfo()

showEquipnfo()

College()

laboratory

Lab_No : Integer

Building : String

Lab_Incharge_Name : String

Status : String

addequipments()

removeequipmqnts()

statusoflab()

lshowequipinfo()

labinfo()

facultyinfo()

1..*1..*

1..*1..*

must have

1

1..*

1

1..*

part of

Page 30: OOAD

5th

Semester OOAD Lab.

CS&E. 30

2.Object Diagram

Main Server

1

IBM Server

purchaseequipment()

equipinfo()

SIT

10

Siddaganga Institute of Technology

Tumkur

displaycollegeinfo()

showlabinfo()

showEquipnfo()

College()

MCA Lab

05

Architecture Block

AGK

Working

addequipments()

removeequipmqnts()

statusoflab()

lshowequipinfo()

labinfo()

facultyinfo()

1..*1..*

1..*1..*

must have

1

1..*

1

1..*

part of

Page 31: OOAD

5th

Semester OOAD Lab.

CS&E. 31

3. INTERACTION DIAGRAM:

(a). Sequence diagram:

user : usercollege :

College

laboratory :

laboratory

equipments :

equipments

request college info

access equip info

college info

return info

request lab info

request for lab info

return info

return lab info

request equip info

request equip info

return result

return equip info

Page 32: OOAD

5th

Semester OOAD Lab.

CS&E. 32

b. Collaboration diagram:

user : user

college : College

laboratory : laboratory

equipments : equipments

1: request college info3: request lab info

7: request equip info

2: college info6: return lab info

12: return equip info

4: request for lab info8: request equip info

5: return info11: return result

9: access equip info

10: return info

5. Deployment diagram.

College Information

System

college

Page 33: OOAD

5th

Semester OOAD Lab.

CS&E. 33

Problem 11: OOA AND OOD USING UML VIII

C Library information system:

A library lends books and magazines to members, who are registered in the system. Also, it

handles the purchase of new titles for the library. Popular titles are bought in multiple copies.

Old books and magazines are removed when they are out if date or in poor condition. A member

can reserve a book or magazine that is not currently available in the library, so that when it is

returned or purchased by the library, that person is notified. The library can easily create, replace

and delete information about the titles, members, loans and reservations in the system.

For the above problem specification devise the following UML diagrams:

1. Use case diagram.

2. Class diagram.

3. State Transition diagram.

4. Sequence diagram.

5. Collaboration diagram.

6. Activity diagram.

7. Component diagram.

8. Deployment diagram.

Page 34: OOAD

5th

Semester OOAD Lab.

CS&E. 34

1. Use case diagram:

Removal

Titlesuses

Magazines

Lends

Reservation

<<uses>>

Purchase

<<uses>>

<<uses>>

Database

Member

Librarian

Notify

Master Regis teration cont rol

Loan

Page 35: OOAD

5th

Semester OOAD Lab.

CS&E. 35

Documentation:

1. Use case name: Lends-this use case is used to lend books/magazines to members

2. Use case name: Master registration control - This use case is used to create, delete and

replace titles, members, and loans.

3. Use case name: Titles - This use case contains the information about books.

4. Use case name: Loan - This use case contains the loan details of books.

5. Use case name: Removal - Removal of books /magazines is done if they are out of date or in

poor condition.

6. Use case name: Reservation - This use case handles the reservation of books by the member

in case titles/magazines not available or given to another member.

7. Use case name: Magazines - This use case contains information about the magazines that are

purchased or reserved.

8. Use case name: Purchase - Librarian purchases books/magazines.

9. Use case name: Notify - Librarian notifies the member if book is purchased or returned and

updated in the database.

10. Actor: Librarian - this actor manages the master registration control, purchase,

reservations, notifications and lends books to the registered members.

11. Actor: Member - Members borrow books from library, reserves books if not available and

returns books

12. Actor: Database - This actor contains all information about titles, magazines, members,

and loans.

Page 36: OOAD

5th

Semester OOAD Lab.

CS&E. 36

2. Class diagram:

DATABASE

LIBRARIAN

name

lends()

purchases()

removes()

notify()

create()

replace()

delete()

*

1

ME MBER

Name

memberid

reserves()

*11 *

1

*

3.State Transition diagram:

Page 37: OOAD

5th

Semester OOAD Lab.

CS&E. 37

3. Sequence diagram:

Member Librarian Database

If book available

request for books /magazines

checks if books/magazines are available

books /magazines available

lends books/magazines to members

Page 38: OOAD

5th

Semester OOAD Lab.

CS&E. 38

Member Librarian Database

If book not available

Requests for books/magazines

checks if book/magazine is available

book not available

waits t il l book/magazine is purchased or returned back by other members

checks again

book available

notifies the member

Page 39: OOAD

5th

Semester OOAD Lab.

CS&E. 39

5. Collaboration diagram: (a)If books available:

M em ber Librarian

Databas e

1: reques t for book s /m agaz ines

4: lends book s /m agaz ines to m em bers

2: c hec k s if book s /m agaz ines are ava ilab le

3: book s /m agaz ines ava ilab le

Page 40: OOAD

5th

Semester OOAD Lab.

CS&E. 40

Collaboration diagram: (b)If books not available:

Member Librarian

Databas

e

4: waits till book/magazine is purchased or returned back by other members

1: Requests for books/magazines

7: notifies the member

2: checks if book/magazine is available5: checks again

3: book not available6: book available

Page 41: OOAD

5th

Semester OOAD Lab.

CS&E. 41

6. Activity diagram:

Librarian handles the creation,deletion,modification of titles,loans,members and

reservations.He handles the purchase,removal of books.he lends books to members.

Member requests for

books/magazines

Book available?

Member reserves

book/magazines

Wait for other member to return book or

purchase of new book by the librarian

Librarian notifies the member

after the arrival of book

Librarian lends the

books to members

no

yes

Page 42: OOAD

5th

Semester OOAD Lab.

CS&E. 42

7. Component diagram:

Database

Librarian Member

8. Deployment diagram:

Library information

system

Library

Library uses library information system

Page 43: OOAD

5th

Semester OOAD Lab.

CS&E. 43

Problem 12: OOA AND OOD USING UML IX

Write the UML diagram for Railway Reservation System Develop the product using the

java program.

USE CASE DIAGRAM:

Verification

Availability and reserve the seats

<<uses>>

Payment detai ls

<<uses>>

Print details

<<uses>>

clerkPassenger

Fill the form details

Fill Form:- Passenger details such as, name, age, sex, place, address, destination, train name are

filled.

Availability and Reservation of seats:- The number of seats available are checked, and

reserved according to the availability.

Verification:- Availability and Reservation of seats use case uses verification use case to verify

the seats available.

Payment Details:- Details of the payment to be made by the passenger are maintained.

Print details:- Details of the passenger is displayed after reservation.

Page 44: OOAD

5th

Semester OOAD Lab.

CS&E. 44

CLASS DIAGRAM:

Passenger

Name : String

Sex : String

Age : Integer

Place : String

Train name : String

To : String

Number of passengers : Integer

psg()calculation()

details()

display()

display1()

Only Passenger class is used. It contains details of the passenger such as name, sex, age, place,

train name, to.

The method psg() is used to accept the passenger details such as number of passengers, place,

train name, destination

The method calculation() is used to check the availability of seats and calculate the amount.

The method details() is used to accept details of each passenger such as name, age, sex.

The method display() is used to display name, age and sex of the passenger.

The method display1() is used to display train name, place, destination.

Page 45: OOAD

5th

Semester OOAD Lab.

CS&E. 45

Java Program: import java.io.*;

import java.lang.*;

class Passenger

{

String name;

String sex;

int age;

String place;

String trainname;

String to;

int seat=10;

int num;

DataInputStream d= new DataInputStream(System.in);

void psg()

{

try

{

System.out.println("Enter The No. Of Passenger:");

num=Integer.parseInt(d.readLine());

calculation();

System.out.println("ENTER THE PLACE:");

place=d.readLine();

System.out.println("Enter The Trainname:");

trainname=d.readLine();

System.out.println("Enter The Destination :");

to=d.readLine();

}

catch(Exception e){ }

}

void calculation()

{

if (num > seat)

{

System.out.println("Seats not available");

System.exit(0);

}

else

{

System.out.println("Seats available");

System.out.println("Rate per Seat:Rs.30");

int price=num * 30;

System.out.println("Total Amount: Rs."+price);

}

}

Page 46: OOAD

5th

Semester OOAD Lab.

CS&E. 46

void details()

{

try

{

System.out.println("Enter Name Of Passenger:");

name=d.readLine();

System.out.println("Enter Age Of Passenger:");

age=Integer.parseInt(d.readLine());

System.out.println("Enter Sex (m/f):");

sex=d.readLine();

}

catch(Exception e){ }

}

void display()

{

System.out.println("Name Of Passenger:"+name);

System.out.println("Age Of Passenger:"+age);

System.out.println("Sex Of Passenger:"+sex);

}

void display1()

{

System.out.println("\nPlace Of Passenger:"+place);

System.out.println("Train Name:"+trainname);

System.out.println("Destination:"+to);

}

public static void main(String arg[])

{

int n;

Passenger p=new Passenger();

p.psg();

n=p.num;

Passenger p1[]= new Passenger[10];

for(int i=1;i<=n;i++)

{

p1[i]=new Passenger();

System.out.println("\nEnter Details Of Passenger:"+i);

p1[i].details();

}

p.display1();

for(int i=1;i<=n;i++)

{

System.out.println("\nDETAILS OF PASSENGER "+i);

p1[i].display();

}

}

}