Vous êtes sur la page 1sur 46

5th Semester OOAD Lab.

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.

Javax.swing.Jfr
Super class
ame

Subclass Ruled class

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.

JFrame Window
Adapter

Ruled Window
Handler

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

CS&E. 1
5th Semester OOAD Lab.

Use case Diagram:


Class Diagram:

Horizontal
Draw Line Set Dimension (from Logical View)

Horizontal()
paint()
main()
<<derive>> <<extend>> jblnit()

Programmer

<<derive>>
Grid Create & Handle Window

Sequence Diagram:

Horizontal java.awt.* javax.swing.JFr java.awt.Dimen java.FileInputSt


ame sion ream

1: setBackground()

2: setForeground()

3: drawline()

4: setTitle()

5: setBounds()

6: setContentPane()
7: setSize()
8: show()

CS&E. 2
5th Semester OOAD Lab.

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

CS&E. 3
5th Semester OOAD Lab.

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:

Draw Line Set Dimension

<<derive>> <<extend>>
Programmer

<<derive>>
Grid Create & Handle Window

Class Diagram:

Crossed

Crossed()
paint()
main()
jbInit()

CS&E. 4
5th Semester OOAD Lab.

Sequence Diagram:

Crossed java.awt.* javax.swing.JFr java.awt.Dimen java.FileInputSt


ame sion ream

1: setBackground()

2: setForeground()

3: drawline()

4: setTitle()

5: setBounds()

6: setContentPane()
7: setSize()
8: show()

CS&E. 5
5th Semester OOAD Lab.

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

CS&E. 6
5th Semester OOAD Lab.

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:

<<extend>>

Interview Vacancy Notice

Offerletter Recommends
Candidate HR Head Employee

Shortlist Bonus

CS&E. 7
5th Semester OOAD Lab.

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:

CS&E. 8
5th Semester OOAD Lab.

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

CS&E. 9
5th Semester OOAD Lab.

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

Ent er st udent information

Calculate t he marks
User

Display results

CS&E. 10
5th Semester OOAD Lab.

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 ().

CS&E. 11
5th Semester OOAD Lab.

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.

CS&E. 12
5th Semester OOAD Lab.

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

CS&E. 13
5th Semester OOAD Lab.

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.

CS&E. 14
5th Semester OOAD Lab.

Activity Diagram:

Enter Student Marks

Calculat e Res ult


USER

Display Result

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.

CS&E. 15
5th Semester OOAD Lab.

Class Diagram:

St udent
reg_no : String
student_name : String <<static>>
<<array>> subject : Object Subject
<<array>> marks : Integer
<<static>> subjectCode : String
<<array>> result : String
<<static>> subject_title : String
total_marks : integer
1..* * <<static>> minimum_marks : integer
<<static>> maximum_marks : integer
calculate_result()
calculate_total()
<<cons tructor>> Subject()
<<constructor>> Student()
Display()
Enter_student_marks()

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.

CS&E. 16
5th Semester OOAD Lab.

Sequence Diagram:

Student : Subject :
Student Subjec t

1: Initialise St udent { 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

CS&E. 17
5th Semester OOAD Lab.

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";
}

CS&E. 18
5th Semester OOAD Lab.

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

CS&E. 19
5th Semester OOAD Lab.

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:

Display the attributes

Customer 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.

CS&E. 20
5th Semester OOAD Lab.

Class Diagram:

Television
Make : Integer
ScreenSize : Integer Customer
PurchaseDate : java.sql.Date
color : String 1..* 1..*
main()
Display()
Television()

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:

C us tom er Televis ion

Reques t for the Details

D is play bac k the D etails

CS&E. 21
5th Semester OOAD Lab.

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

CS&E. 22
5th Semester OOAD Lab.

public class Customer


{
public static void main(String args[])
{
Television t = new Television();
t.Display();
}
}

CS&E. 23
5th Semester OOAD Lab.

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.

D e po s it
p rinc ipl e : floa t
ra te : fl oat
n o_o f_y ea r s : i nt
s im p le_ i nt : fl oa t
a m oun t : float

De pos i t()
d is pl a y ()

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;

CS&E. 24
5th Semester OOAD Lab.

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

CS&E. 25
5th Semester OOAD Lab.

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:

Customer Account Deposit

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:
Object name User ID FName LName DOB Address Phone no

Address:

Object name Street City State Country Pin code

CS&E. 26
5th Semester OOAD Lab.

Class Diagram:

Customer
Customer Id : String Account
First Name : String
Acc NO : Long
Last Name : String
Users : Integer
Phone No : Integer +Has Cust[Users] : Object
DOB : String
1.. * Deposit : Object
Address : Object 1..*
Open_Account()
Display_Customer_Info()
Deposit_Money()
Accept_Customer_Info()
Get_Customer_Details()

Deposit
Address Principle : Double
Street : String No of Years : Integer
City : S tring Rate Of Interest : Double
State : S tring Simple Interest : Double
Country : St ring Amount : Double
PIN : Int eger
Calculate_Interest()
Get_Address() Calculate_Amount()

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.

CS&E. 27
5th Semester OOAD Lab.

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.

CS&E. 28
5th Semester OOAD Lab.

Class Diagram

College
College_id : Integer
College_Name : String
Address : String
displaycollegeinfo()
showlabinfo()
showEquipnfo()
College()

1
part of

1..*
laboratory
Lab_No : Integer
Building : String
Lab_Incharge_Name : String equipments
Status : String Equipment No : Integer
addequipments () Equipment : String
removeequipmqnts() must have 1..*
1..* purchaseequipment()
statusoflab() equipinfo()
lshowequipinfo()
labinfo()
facult yinfo()

CS&E. 29
5th Semester OOAD Lab.

2.Object Diagram

SIT
10
Siddaganga Institute of Technology
Tumkur
displaycollegeinfo()
showlabinfo()
showEquipnfo()
College()
1
part of

1..*
MCA Lab
05
Architecture Block
AGK Main Server
Working
1
addequipments()
IBM Server
removeequipmqnts() must have 1..*
1..* purchaseequipment()
statusoflab()
equipinfo()
lshowequipinfo()
labinfo()
facultyinfo()

CS&E. 30
5th Semester OOAD Lab.

3. INTERACTION DIAGRAM:

(a). Sequence diagram:

user : user equipments :


college : laboratory :
College laboratory equipment s
request college info
college info

request lab info

request for lab info

ret urn info

return lab info

request equip info

request equip info

acc ess equip info

return info

ret urn result

return equip info

CS&E. 31
5th Semester OOAD Lab.

b. Collaboration diagram:

1: request college info


3: request lab info
7: request equip info
college :
College
2: college info
user : user 6: return lab info
12: return equip info

5: return info
11: return result

4: request for lab info


8: request equip info

9: access equip info


laboratory : equipments :
laboratory equipments
10: return info

5. Deployment diagram.

college
College Information
System

CS&E. 32
5th Semester OOAD Lab.

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.

CS&E. 33
5th Semester OOAD Lab.

1. Use case diagram:

Lends

Master Regis teration cont rol

Database
uses Titles
Loan
Librarian

Member
Removal Reservation

<<uses>>

<<uses>>
Magazines

<<uses>>

Purchase

Notify

CS&E. 34
5th Semester OOAD Lab.

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.

CS&E. 35
5th Semester OOAD Lab.

2. Class diagram:

DATABASE

1
LIBR ARIAN
name
ME MBER
lends()
Name
purchases()
memberid
removes()
1 *
notify()
reserves()
create()
replace ()
delete()

3.State Transition diagram:

CS&E. 36
5th Semester OOAD Lab.

3. Sequence diagram:

If book available

Member Librarian Database

request for books /magazines

checks if books/magazines are available

books /magazines available

lends books/magazines to members

CS&E. 37
5th Semester OOAD Lab.

If book not available

Member Librarian Database

Requests for books/magazines

checks if book/magazine is available

book not available

wait s t ill book/ magazine is purchased or returned back by ot her members

checks again

book available

notifies the member

CS&E. 38
5th Semester OOAD Lab.

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

1 : re qu es t for b oo k s /m ag az in es

M em b er Libra ria n

4: le nd s b oo k s /m ag az in es to m e m b ers

3: b oo k s /m ag az in es ava ilab le

2 : c he c k s if b oo k s /m ag az ine s are ava ilab le

D a tab as e

CS&E. 39
5th Semester OOAD Lab.

Collaboration diagram: (b)If books not available:

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

1: Requests for books/magazines


Member Librarian

7: notifies the member

3: book not available


6: book available

2: checks if book/magazine is available


5: checks again

Databas
e

CS&E. 40
5th Semester OOAD Lab.

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?

yes
no

Member reserves
book/magazines

Wait for other member to return book or


purchase of new book by the librarian

Librarian notifies the member Librarian lends the


after the arrival of book books to members

CS&E. 41
5th Semester OOAD Lab.

7. Component diagram:

Dat abase

Librarian Member

8. Deployment diagram:

Library

Library uses library information system


Library information
system

CS&E. 42
5th Semester OOAD Lab.

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:

Fill the form details

Availability and reserve the seats


<<uses>>
<<uses>>
Passenger
clerk

Verification Payment details

<<uses>>

Print 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.

CS&E. 43
5th Semester OOAD Lab.

CLASS DIAGRAM:

Pas senger
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.

CS&E. 44
5th Semester OOAD Lab.

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

CS&E. 45
5th Semester OOAD Lab.

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

CS&E. 46

Vous aimerez peut-être aussi