101
Object oriented analysis and design lab report PROGRAM 2: GRID LINES import javax.swing.*; import java.awt.*; import java.awt.event.*; class Design extends JFrame { Container cp; Design() { cp=getContentPane(); cp.setLayout(null); Adapter ad=new Adapter(this); addWindowListener(ad); repaint(); } public void paint(Graphics g) { for(int i=0;i<=800;i+=10) { g.drawLine(i,0,i,800); g.drawLine(0,i,800,i); } } class Adapter extends WindowAdapter { Design dd; public Adapter(Design d) { dd=d; } public void windowClosing(WindowEvent we) { System.exit(0); } } Department of MCA ,MSRIT,Bangalore. 1

Ooad Lab Programs

Embed Size (px)

DESCRIPTION

this is the document for the 5th sem mca students UNDER VTU

Citation preview

Page 1: Ooad Lab Programs

Object oriented analysis and design lab report

PROGRAM 2: GRID LINESimport javax.swing.*;import java.awt.*;import java.awt.event.*;

class Design extends JFrame {

Container cp;Design(){

cp=getContentPane();cp.setLayout(null);Adapter ad=new Adapter(this);addWindowListener(ad);repaint();

}

public void paint(Graphics g){

for(int i=0;i<=800;i+=10){

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

}

}

class Adapter extends WindowAdapter{

Design dd;public Adapter(Design d){

dd=d;}

public void windowClosing(WindowEvent we){

System.exit(0);}

}

public static void main(String s[]){

Design d1=new Design();d1.setSize(500,500);d1.setVisible(true);

}

}

Department of MCA ,MSRIT,Bangalore. 1

Page 2: Ooad Lab Programs

Object oriented analysis and design lab report

PROGRAM 3: GRID WITH TWO SETS OF DIAGONAL LINES

import javax.swing.*;import java.awt.*;import java.awt.event.*;

class Design1 extends JFrame{Container cp;Design1(){cp=getContentPane();cp.setLayout(null);Adapter ad=new Adapter(this);addWindowListener(ad);repaint();}

public void paint(Graphics g){for(int i=0,j=1000;i<=1000;i+=10,j-=10){g.drawLine(0,i,i,0);g.drawLine(i,0,1000,j);g.drawLine(0,i,j,1000);}}

class Adapter extends WindowAdapter{Design1 dd;public Adapter(Design1 d){dd=d;}

public void windowClosing(WindowEvent we){System.exit(0);}}

public static void main(String s[]){Design1 d1=new Design1();d1.setSize(500,500);d1.setVisible(true);}}

Department of MCA ,MSRIT,Bangalore. 2

Page 3: Ooad Lab Programs

Object oriented analysis and design lab report

PROBLEM 4

Problem definition In employee referral process, the HR head of the region where a vacancy exists informs employees of that region and other regional HR heads. The other regional HR heads 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 the vacant position and shortlist them. An interview schedule is drawn up and the short listed candidates are informed. Based on the interview processing, interview details are updated and all the selected candidates are given offer letter. The candidate informs the HR (head where the vacancy exists) 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 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.

REQUIREMENTS SPECIFICATION

The process shall result in the recruitment of employees for the vacancy that has become available in a particular region.

The total candidates considered for the process shall be made available by a referral system from the existing employees of the organization.

The HR head of a particular region shall inform details about the vacancy to employees of his/her region and also inform the other HR heads of the same vacancy.

The references from the other HR heads shall be made available to the region that has the vacancy.

The candidates that meet the requirements of the vacancy shall be short listed for the selection process.

The interview process is conducted and the candidates are selected to meet the vacancy of the region.

The selected candidates are informed and are requested to accept the job offer.

Based on whether the candidate accepts the job offer bonuses shall be awarded to the employee that referred the candidate.

Department of MCA ,MSRIT,Bangalore. 3

Page 4: Ooad Lab Programs

Object oriented analysis and design lab report

Actors:

Actors are as follows:

1.HR Head.

2.Employee.

3.Candidates.

Actors Documentation:

1.HR Head: HR Head is an actor who informs about the vacancy to their employees and also other regional HR Heads, who in turn informs their respective Employees and also matches the skills of the referred Candidates with their skills, required for the vacant position and shortlist them. HR Head is also responsible for Interview Scheduling.

2.Employee: Employee is an actor who references the Candidates regardless of his/her region and receives the incentives provided the referred Candidate got selected

3.Candidate:

Candidate is an actor who is referred by an Employee of the Company and applies

for the vacancy. If the Candidate gets selected then they informs the HR Head about the

acceptance or rejection of the offer letter.

Department of MCA ,MSRIT,Bangalore. 4

Page 5: Ooad Lab Programs

Object oriented analysis and design lab report

Use-Case Diagram:

Department of MCA ,MSRIT,Bangalore. 5

Page 6: Ooad Lab Programs

Object oriented analysis and design lab report

USE CASES:

Use Case: Notify VacancyDescription : This Use Case is initiated by HR and the Employee.

Notifies about the vacancies to employees of the region.Flow of Events: 1. HR Head sends Email notification to his/her employees.

2. HR Head informs about vacancy to other region HR heads. 3. Other HR heads in turn inform their employees.

Pre-Condition: Vacancy must exist.Post-Condition: Details about the vacancy are informed.

Use Case: Filling of FormsDescription: This Use Case is initiated by HR and the Employee.

Online forms are filled by the employees.HR head processes the forms and determines eligible candidates.

Flow of Events: 1. Employees fill out online forms of candidates they want to refer.2. HR head processes the filled forms.3. HR heads selects the list of eligible candidates.

Pre-Condition: Online form must exist.Post-Condition: Forms filled are stored in a Information System for processing.

The filled forms are sent to the HR.The HR head produces the list of eligible candidates.

.

Use Case: Short Listing of CandidatesDescription This Use Case is initiated by Candidate and HR.

The Interviews are conducted by the HR head of the region that has the vacancy. The list of selected candidates are obtained after the interview process.

Flow of Events: 1. HR head schedules the interview process.2. HR head conducts the interview for the candidates via online system.3. Candidates who clear the interview process are selected.

Pre-Condition: Candidate must meet eligibility criteria.Candidate must be referenced by the employee of that organization.

Post-Condition Candidate clears interview process.ORCandidate doesn’t clear interview process.

Department of MCA ,MSRIT,Bangalore. 6

Page 7: Ooad Lab Programs

Object oriented analysis and design lab report

Use Case : Intimation to the selected candidates.Description: This Use Case is initiated by the HR Head and the Candidate

The candidate accepts or rejects the offer letter to fill the vacancy.Bonus is awarded to the employee who referred the candidate.

Flow of Events 1. Candidate is informed about selection the job.2. Candidate accepts the job offer to fill the vacancy.3. Bonus is awarded to the employee who referred the candidate.

Alternate Flow 1. Candidate rejects the offer letter.2. Candidate application is rejected.3. No Bonus is awarded to the employee who referred the candidate.

Pre-Condition: Candidate is selected for the job.Post-Condition: Candidate accepts or rejects the offer.

Bonus is awarded to the employee who referred the candidate if he/she accepts the offer.

Sequence Diagram:

Notify Vacancy:

Department of MCA ,MSRIT,Bangalore. 7

Page 8: Ooad Lab Programs

Object oriented analysis and design lab report

Fill Referral Process:

Selection of Candidates:

Department of MCA ,MSRIT,Bangalore. 8

Page 9: Ooad Lab Programs

Object oriented analysis and design lab report

Intimation [Accepts Offer Letter]:

Intimation [Rejection]:

Department of MCA ,MSRIT,Bangalore. 9

Page 10: Ooad Lab Programs

Object oriented analysis and design lab report

CLASS DIAGRAM

EmployeeFname : StringLName : StringEmp-ID : intDesignation : Stringregion : string

ReferCandidate()GetBonus()

Selected Candidates

CandidateID : int

Accept()Reject()

Vacany DetailsJobCode : intDesignation : StringDescription : StringNo.ofVacantPos : int

Prerequisits()

Recruited Candidates

CandidateID : int

FillVacancy()

MaintainenceEmployee eCandidate c

Insert()Update()Delete()

HR HeadEmployee eCandidate c

InformVacancy()ConductInteview()ShortList Candidates()Intimate Candidates()

CandidateFname : StringLName : stringCandidateID : intJobCode : int

apply()

Department of MCA ,MSRIT,Bangalore. 10

Page 11: Ooad Lab Programs

Object oriented analysis and design lab report

Class Diagram Documentation

Employee:The employee class is used to store details about the employees of a particular

region. This information shall be used later to award bonuses provided the candidates they refer get selected to fill the job vacancy.

HR Head:This class is the main class. The HR is responsible for collecting the details of the

candidates being referred. It is also the HR job to conduct the interview, shortlist the candidates and also intimate the selected candidates about the job.

Maintenance:The Maintenance class is responsible for maintaining the Information System(IS)

where the information about the candidates and the employees are stored.

Vacancy Details:This class contains the details of the vacancy that are to be filled. Here a Job Code

is assigned to keep information about each vacancy detailing the type of job, the designation and the No. Of vacant posts.

Candidate:The candidate class contains the details about the candidates being referred by the

employees. The information about the job they have applied for (Job Code) is also stored.

Selected Candidates:This class contains the details of the selected candidates after the Interview

process.

Recruited CandidatesThis class contains details of the candidates who accepted the offer letters and are

ready to fill the vacancy. This information shall be used to award bonuses to the employees who referred the candidates.

Department of MCA ,MSRIT,Bangalore. 11

Page 12: Ooad Lab Programs

Object oriented analysis and design lab report

PROGRAM 5

Design and implement a student class with the following attributes:

1) Reg No.

2) Name of the student

3) Marks in subject1, subject2, subject3

4) Total Marks

The total of three subject marks must be calculated only when the student pass in all the

subject. The pass marks for each subject is 50. If a candidate fails in any one of the

subjects, his total marks must be declared as 0. Using this condition write a constructer

for this class. Write a method display a student() to display the details of the student of

the object.

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

the system.

b) Identify various class and attributes and bring out class diagram and

sequence diagram.

Description

In this problem the students interact with the system to see their results. Faculty is the

person who use the software system to enter student’s marks in the system and according

to these marks result is prepared based on the condition that, the total of three subject

marks must be calculated only when the student pass in all the subject. The pass marks

for each subject is 50. If a candidate fails in any one of the subjects, his total marks must

be declared as 0.

Requirement Specification

The system shall accept the marks from the faculty for each student.

The system shall be able to calculate result according to the marks entered and the

condition to declare the result.

Both student and faculty shall see the result.

Department of MCA ,MSRIT,Bangalore. 12

Page 13: Ooad Lab Programs

Object oriented analysis and design lab report

Actors and actor documentation

Faculty: It refers to the person who enters the marks and calculates the result.

Student: The student uses the system to view their result.

Use case diagram

marks processing

result processing

<<extends>>

student

display result

faculty

Use case documentation

Marks processing

1. Description: Initiated by the faculty to enter the marks.

2. Precondition: -

3. Normal Flow of Event:

Enter name of the student.

Enter registration number of the student.

Store name and registration number in the database.

Enter marks.

Store marks to the database.

4. Alternate flow of event: -

5. Post condition: -

Department of MCA ,MSRIT,Bangalore. 13

Page 14: Ooad Lab Programs

Object oriented analysis and design lab report

Result Processing

1. Description: Initiated by faculty to evaluate result.

2. Precondition:

3. Normal Flow of Event:

Enter name of the student.

Enter regno of the student.

Search for name and regno from the database.

Retrieve marks from the database and send to the information system.

The total of three subject marks is calculated only when the student pass

in the entire subject. The pass marks for each subject is 50.

4. Alternate flow of event: If a candidate fails in any one of the subjects, his total

marks must be declared as 0.

5. Post condition: Store in the database.

Display result

1. Description: Initiated by both student and faculty.

2. Precondition: -

3. Normal Flow of Event:

Enter name of the student.

Enter registration number of the student.

Search name and registration number from the database.

Retrieve result and send to the information system.

Display result.

4. Alternate flow of event: -

5. Post condition: -

Sequence diagrams

1. Sequence diagram for marks processing:-

Department of MCA ,MSRIT,Bangalore. 14

Page 15: Ooad Lab Programs

Object oriented analysis and design lab report

faculty database

Information Syste...

1: request for regno and name

2: Enter name and regno

3: Save in database

4: Request for marks

5: Enter marks

6: Save marks

2. Sequence diagram for result processing:

faculty databaseInformation syste...

1: Request for name and regno

2: Enter name and regno

3: Search for name and regno

4: retrieve marks

5: Provide marks to system

6: Evaluate result and save

3. Sequence diagram for displaying result:

Department of MCA ,MSRIT,Bangalore. 15

Page 16: Ooad Lab Programs

Object oriented analysis and design lab report

student databaseinformation syste...

1: Enter name and regno

2: Search name and regno

3: retrieve result

4: Send result

5: Display result

Cass diagram

Class Documentation

Student:

Student1 class maintains the attributes of student details such as student name reg_no

marks of the three subjects and total marks of those students who have passed in all

the three subjects and use to view the result and detail of the students.

Java code

class student

Department of MCA ,MSRIT,Bangalore. 16

Page 17: Ooad Lab Programs

Object oriented analysis and design lab report

{

int reg_no;

String name;

int marks[ ]=new int[3];

int total;

student(int r,String n,int m[])

{

reg_no=r;

name=n;

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

marks[i]=m[i];

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

{

if(marks[i]>50)

total+=marks[i];

else

{

total=0;

break;

}

}

}

void display()

{

System.out.println("\nReg no : "+reg_no);

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

System.out.println("Marks in subject1 : "+marks[0]);

System.out.println("Marks in subject2 : "+marks[1]);

System.out.println("Marks in subject2 : "+marks[1]);

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

}

public static void main(String s[])

{

int a[]={55,67,89};

Department of MCA ,MSRIT,Bangalore. 17

Page 18: Ooad Lab Programs

Object oriented analysis and design lab report

int b[]={6,90,90};

int c[]={89,87,67};

student ob1=new student(101,"Manu",a);

student ob2=new student(102,"madhu",b);

student ob3=new student(103,"Raju",c);

ob1.display();

ob2.display();

ob3.display();

}

}

PROGRAM 6

Problem definition:

Department of MCA ,MSRIT,Bangalore. 18

Page 19: Ooad Lab Programs

Object oriented analysis and design lab report

Consider the student class defined in Problem 5. Assume that a student studies 6 subjects. Each subject has a title, passing minimum 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 50 100CS406 ASW lab 18 50-------- --------- ---- ----You must first define a class called subject. For every student there is an array of 6 subjects. Since all the students study the same subjects, we declare it as static. The student class will have the following attributes: Reg_no, name, subject array, marks array, result array and total.

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.

Solution

The purpose of the system is to process marks of individual students in order to determine whether the particular student has passed or not in the exams and also produce a formatted report of the same.

The following requirements are identified with respect to the system

The system shall process marks of the student. Based on the mark information provided by faculty the total marks of each student

must be obtained along with results. Student result details shall be provided in neatly formatted report for viewing. While calculating the results the following points are considered

i. A student has to study six subjects, each subject has a passing minimum and maximum marks.

ii. The total of marks of each student will be calculated only when he/she passes in all the six subjects.

iii. The passing mark in each subject is 50% of the maximum mark.iv. If the candidate fails in any one of the subject the total marks is taken to be zero.

The system must be interactive and suitable user authentication mechanism must be incorporated.

Actor Documentation

Actors:

Department of MCA ,MSRIT,Bangalore. 19

Page 20: Ooad Lab Programs

Object oriented analysis and design lab report

Student : they use the system primarily to check their results.

Faculty: provides the marks of each student for processing the results.

Usecase Diagram:

STUDENT ENTER MARKS

FACULTY

MARKS PROCESSING

<<USES>>

VIEW REPORTS

LOGIN

<<USES>><<USES>>

Usecase documentation:

1 Usecase name: Login

The users of the system either faculty or student interact with the system by going through a login process to verify their authentication.

Precondition: Each user who wants to use the system must posses a username & password. Flow Of Events:

1. Request user name. 2. Enter username.3. Request password.4. Enter password.5. Validate user.6. If valid continue otherwise go to Alternate flow 1.

Alternate Flow 1: Display error message

2: Reenter username and password.Postcondition: User is allowed or not allowed to login based on the provided username & password.

Department of MCA ,MSRIT,Bangalore. 20

Page 21: Ooad Lab Programs

Object oriented analysis and design lab report

2.Usecase name: Marks Processing

Faculty using the system initiates this process. During this stage the total and results of each student is calculated based on marks entered.Precondition: Valid marks of each student should be present in order to obtain results.Flow Of Events:

1. Request register number of the student for whom marks as to be entered.

2. Enter register number.3. Validate register number.4. If valid, perform marks entry process, Otherwise go to

Alternate flow 1.5. Compute total.6. Compute Result for the student who’s register number has

been entered. Alternate Flow 1: Display Error Message. Request another register number. Postcondition: Based on the constraints specified and marks, results of each student are provided.

3.Usecase name: Marks Entry

Marks of each student are entered by the faculty during this process. Marks entered during this stage are used while calculating results.

Precondition : Marks are needed to calculate result. Flow of Events:

1. Request entry of marks.2. Enter marks.3. Verify whether entered marks are valid,

If valid continue otherwise Alternate flow 3. Alternate flow 3: Display error message, re-enter marks. Postcondition: Enter marks are verified and are stored to perform processing. 4.Usecase name: View Reports

Students interact with system for the purpose of determining their results. The results are presented in the form of reports, for viewing by the students.

Precondition: Students specify their Regno. to view results. Flow of Events:

1. Request register number of the student.2. Enter register number.3. Verify register number.4. if valid display reports of the result otherwise Alternate

flow 4. Alternate flow 4: Display error message, reenter register number. Postcondition: Result of the student is displayed in a formatted manner.

Sequence Diagrams:

Sequence diagram for Marks entry and Marks Processing

Department of MCA ,MSRIT,Bangalore. 21

Page 22: Ooad Lab Programs

Object oriented analysis and design lab report

FacultySystem :

NewInterface

Database

1: Requrest Regester Number

2: Enter Regester Number

3: Verify

4: Found Valid

5: Request Entry Of Marks

6: Enter Marks

7: Verify Entered Marks

8: Update New Marks

9: Transaction Successful

10: View Message

11: Terminate

Department of MCA ,MSRIT,Bangalore. 22

Page 23: Ooad Lab Programs

Object oriented analysis and design lab report

Sequence diagram for Login

User System

2: Enter user name and password

1: Request user name and password

3: Not valid

5: Enter user name and password

4: Request re-entry

6: Valid user

7: Perform operations

Sequence Diagram For Viewing Reports:-

StudentSystem :

NewInterface

Database

1: Request Register Number

2: Register Number Entry

3: Verify

7: View Marks Report

5: Reterive

6: Send Details

4: Found Valid

Department of MCA ,MSRIT,Bangalore. 23

Page 24: Ooad Lab Programs

Object oriented analysis and design lab report

Class Diagram

SubjectSub_name : StringSub_code : Stringtheory_max : Integertheory_min : Integerlab_max : Integerlab_min : Integer

Facultysub1[] : Integersub2[] : Integersub3[] : Integersub4[] : Integersub5[] : Integersub6[] : Integer

faculty_login()get_regno()enter_marks()

StudentRegno : IntegerName : StringMarks[] : IntegerSubject[] : Stringtotal : Integerresult : String

student_login()get_details()get_marks()compute_result()view_reports()

Provides Marks details

Derives Subject Info

Derives Subject Info

Class Diagram Documentation

1. Class Name: Student

Student class maintains all the attributes indicating the student details and incorporates the necessary methods required to access the results, compute results and view reports.

2. Class Name: Subject

Subject class maintains all the details related to subject studied by the students, the marks details of each Subject.

3.Class Name: Faculty

Faculty operation details are maintained in this class, they login to the system to enter the mark details of the students based on the students register number, once entered the marks details are stored into individual marks array in the student class.

Department of MCA ,MSRIT,Bangalore. 24

Page 25: Ooad Lab Programs

Object oriented analysis and design lab report

Program

import java.io.*;

class Subject { static String sub_name[]={"java","c++","ooad","dbms","ooad lab","java lab"}; static String sub_code[]={"Mca51","Mca52","Mca53","Mca54","Mca55","Mca56"}; static int theory_max=100, lab_max=50; static int theory_min=50, lab_min=25;

// attributes are declared static so they can be accessed without inheritance}

class Marks_details{ int sub1[]=new int [20]; // each array contains the marks details of one particular int sub2[]=new int[20]; // subject, the marks are stored such that each array index int sub3[]=new int [20]; //corresponds to a students register number int sub4[]=new int [20]; int sub5[]=new int [20];//first 3 arrays store marks in theory next 2 store lab marks int sub6[]=new int [20]; void enter_marks()

{ int reg; try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter number of student"); String temp=br.readLine(); int n=Integer.parseInt(temp); for(int i=0;i<n;i++) { // Each value of i is used as register number System.out.println("Enter marks for student with register number " +(i+1) ); System.out.println("Enter marks in MCA51:"); temp=br.readLine(); sub1[i]=Integer.parseInt(temp); System.out.println("Enter marks in MCA52:"); temp=br.readLine(); sub2[i]=Integer.parseInt(temp); System.out.println("Enter marks in MCA53:"); temp=br.readLine(); sub3[i]=Integer.parseInt(temp); System.out.println("Enter marks in MCA54:"); temp=br.readLine(); sub4[i]=Integer.parseInt(temp);

System.out.println("Enter marks in MCA55:"); temp=br.readLine(); sub5[i]=Integer.parseInt(temp);

Department of MCA ,MSRIT,Bangalore. 25

Page 26: Ooad Lab Programs

Object oriented analysis and design lab report

System.out.println("Enter marks in MCA56:"); temp=br.readLine(); sub6[i]=Integer.parseInt(temp); }

} catch(Exception e){ } }}

class Student extends Marks_details{

String Name;int reg;int marks[]=new int[6];String subject[] = Subject.sub_name; // accessing static attribute sub_name int total,t;String result;

Student(){reg=-1;total=0;}

int get_details( ){ try

{ BufferedReader b=new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter Register Number");String s=b.readLine();

reg=Integer.parseInt(s);System.out.println("Enter Name");Name=b.readLine();}catch(Exception e){}return (reg);

}

void get_marks(){ marks[0]=sub1[reg-1]; //marks from sub array are stored into marks array marks[1]=sub2[reg-1]; // the regno value r corresponds to the index in marks[2]=sub3[reg-1]; // sub array where marks of this regno will be stored marks[3]=sub4[reg-1]; marks[4]=sub5[reg-1]; marks[5]=sub6[reg-1];//array positions marks[4], marks[5] represent lab marks}

Department of MCA ,MSRIT,Bangalore. 26

Page 27: Ooad Lab Programs

Object oriented analysis and design lab report

void compute_result(){

int f1=0, f2=0;for(int i=0;i<6;i++){total=total+marks[i];}t=total;total=0; //reset totalfor(int k=0;k<4;k++){if(marks[k]< Subject.theory_min) f1=1;}if(marks[4]<Subject.lab_min || marks[5]<Subject.lab_min)f2=1;if(f1==0 && f2==0)result="PASS";elseresult="FAIL";

}

void show_report(){System.out.println("\n"+"_____________________________" + " Student MarksDetails"+ " ___________________________" ); System.out.println("\n" + "Name: " +Name +"\n" +"Reg: " +reg); System.out.println("Sub_code Title Pass_Min Pass_max Marks"); for(int i=0;i<6;i++){ if((i!=4)&&(i!=5))

System.out.println (Subject.sub_code[i] +" \t\t " +subject[i] + " \t\t " +Subject.theory_min +"\t\t" +Subject.theory_max +"\t" +marks[i]);

else

System.out.println (Subject.sub_code [i] +" \t\t " +subject[i] + " \t " +Subject.lab_min +"\t"+"\t"+Subject.lab_max+"\t"+marks[i]);}

System.out.println("Total: " +t);System.out.println("Result :" +result+"\n");

}}

Department of MCA ,MSRIT,Bangalore. 27

Page 28: Ooad Lab Programs

Object oriented analysis and design lab report

class program6{ public static void main(String args[]) {

int ch=0;Student sob=new Student();try{do{ System.out.println("Enter Type of user"); System.out.println("1. Student"); System.out.println("2. Faculty");System.out.println("3. Exit");BufferedReader br=new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter your choice");String temp=br.readLine();ch=Integer.parseInt(temp);switch(ch)

{case 1: int x=sob.get_details();

if(sob.sub1[x-1]==0){

System.out.println("Reg doesnot exist");break;

}sob.get_marks();sob.compute_result();sob.show_report();break;

case 2:sob.enter_marks();break;

}}while(ch!=3);

}catch(Exception e){ }}

}

Department of MCA ,MSRIT,Bangalore. 28

Page 29: Ooad Lab Programs

Object oriented analysis and design lab report

Problem: 7

A class called Television has the following attributes make, screen, size, purchase date, color/black & white. Define a method for displaying attribute values of a TV. Represent this following specification using UML class notations and write a java program for the same. Television class should be designed with the required attributes. The main method should be written to test methods of television class. For example display TV() method may be used to print the attributes of television class.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 sequence

diagram.

Requirements

1. The system should be able to display all the kinds of models available according to particular made (Sony, Samsung…).

2. It should be able to show the stock available based on brand, size, color/black & white ad cost.

3. The user must be authenticated to use the system .

4. The system should be able to display the price list based on the customer Specification.

Actors

Operator: He is the actual user of the system. He interacts with the system to performtransactions such as checking availability of models according to customer specification and displaying price list according customer request.

Department of MCA ,MSRIT,Bangalore. 29

Page 30: Ooad Lab Programs

Object oriented analysis and design lab report

JAVA CODE

class TransactionManager{ String Id="msrit"; String password="msrit"; bool Verify(String user,String pass) { return(user.equals("msrit") && pass.equals("msrit")); }}class Television { String make,date,type; int size; Television() { try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the make:"); make=br.readLine(); System.out.println("Enter the size of T.V."); size=Integer.parseInt(br.readLine()); System.out.println("Enter the date of manufacturing:"); date=br.readLine(); System.out.println("Enter the type"); type=br.readLine(); }catch(Exception e) { } } void display() { System.out.println("Information about the T.V."); System.out.println("--------------------------"); System.out.println("Make of T.V.:"+make); System.out.println("Date of Manufacturing:"+date); System.out.println("Type of the TV:"+type); System.out.println("Size of The TV:"+size); } public static void main(String s[]) { Television t=new Television();

BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String user,pass;

TransactionManager tm=new Transactionmanager(); System.out.println("Enter userid");

user=br.readLine(); System.out.println("Enter password");

password=br.readLine(); if(tm.verify(user,pass)) t.display(); else

System.out.println("Invalid userid/password"); } }

Department of MCA ,MSRIT,Bangalore. 30

Page 31: Ooad Lab Programs

Object oriented analysis and design lab report

Use cases

Use case name: Display TV models

Description: This use case is initiated by operator. The details are obtained from an existing database and display different Television models available according to particular made, screen size...Etc.Normal flow of events : 1. request for details of T.V .

2. request for specific model .3. enter the specific models.4. display the requested models .

Precondition: The models details must exist in the database.

Post condition: Display the models requested.

Use case name: Authentication:

Description: This use case is initiated by operator of the television system. If an operator enters his/her details like operator name, password the system validate the operator for using the system.Normal flow of events : 1. Request for access.

2. Request for Id 3. Enter Id.

4. Request for password. 5. Enter the password. 6. if invalid password or id, go for alternative flow.

Alternative Flow : 1.Display the error message 2. Ask for id and password again.

Precondition: Operator information must exist.Post condition: Access to the television system must be granted.

Use case name: View price list

Description: This use case is initiated by operator of the television system. This usecase displays the price list of the models selected by the customers.Normal flow of events : 1. Request for the price list.

2. Request for the specific model. 3. Enter the specific model. 4. Display the price list.

Precondition: Prices of all models must exist.Post condition: Price list of the specified model is displayed.

.

Department of MCA ,MSRIT,Bangalore. 31

Page 32: Ooad Lab Programs

Object oriented analysis and design lab report

Usecase Diagram

Display Price List

OperatorAuthentication

Display TV Models

<<uses>>

Classes

Television Class: This class has properties tv make, size, purchase_date,color. Make specifies companies name,size specifies size of the television screen,color specifies whether the TV is black & white or color.Methods: TV() is a constructor used to initialize attributes.Displays() displays the attribute values.Check() verifies whether the made,size is available for the customer.

Department of MCA ,MSRIT,Bangalore. 32

Page 33: Ooad Lab Programs

Object oriented analysis and design lab report

Transaction manager:

Transaction manager class is responsible for authenticating the users.It contains attributes such as userid and password.Methods: verify () verifies whether the user is authorized to the system.

OO Testing

There are several ways object-oriented programming can have an impact on testing. Depending on the approach to OOP

Some types of faults become less plausible not worth testing for). Some types of faults become more plausible Worth testing now). Some new types of faults appear.

When an operation is invoked, it may be hard to tell exactly what code gets exercised. That is, operation may belong to one of many classes. Also, it can be hard to determine the exact type or class of a parameter. When the code accesses it, it may get an unexpected value. The difference can be understood by considering a conventional function call.X=func(y);For conventional software, the tester need consider all behaviors attributed to func and nothing more. In an OO context, the tester must consider the behaviors of base::func(), of devired::func(), and so on.

Sequence diagrams

Authentication:

Operator Television Info System

Request for Access

Request for Id and Password

Enter Id and Password

Access Granted

Department of MCA ,MSRIT,Bangalore. 33

Page 34: Ooad Lab Programs

Object oriented analysis and design lab report

Display TV models:

Operator Television Info System

Request for details of TV

Request for Specific Made

Enter Specific Made

Display Model

Display price list

Operator Television Info System

Request for Price List

Request for Specific Model

Enter the Model

Display Pricelist

Department of MCA ,MSRIT,Bangalore. 34

Page 35: Ooad Lab Programs

Object oriented analysis and design lab report

Program 8

Bank Interest Computation

Consider the following attributes:P : Principle AmountR : Rate Of InterestN : Number Of YearsSI : Simple InterestA : Amount

Requirement Specification:

Customer deposits money in the bank. The deposited money is called the Principle Amount.

After authentication and verification of the user, the principle amount and interest is computed and the amount is displayed.

The time in years varies for RD, FD, SB account types and interest is computed based on the following factors: -

Account Type: RD, FD, and SB. Time duration: Monthly, quarterly, half yearly and annually. Minimum Balance: 5000/- SB

10,000/- FD 10,000/- RD

Actors:

Account Holder DBMS Administrator

Actor Documentation:

Account Holder: He or She will have an account in the bank and would be allowed to access the details of their account.

DBMS: It will contain the account holder details. It will display the requested information.

Administrator: He will authorize the access to the account and if verified will provide the account details. He will authenticate, validate, compute, update the interest rates and store the computed results and account holder details in DBMS.

Department of MCA ,MSRIT,Bangalore. 35

Page 36: Ooad Lab Programs

Object oriented analysis and design lab report

USE CASE :

Deposit

Display

Account Holder

Calculate Interest

DBMS

Verify Account

Administrator

Use Case documentation:

Verify Account: This use case is initiated by the Account Holder, Account Holder enters the PIN number.This would be cheked by the administrator fro its existence and correctness and will authenticate the user fro further use of the system.

Deposit Amount: This use case is initiated by the account holder. The account holder will deposit the money using the cheques.

Calculate Interest: This use case is initiated by the Administrator after the authentication of details provided by the account holder. It will then calculate the interest amount according to the factors mentioned in the requirements specification and according to the formulae:

SI = ( P * R *N ) / 100Amount = P + SI

WhereP : Principle Amount

R : Rate Of InterestN : Number Of YearsSI : Simple InterestA : Amount

Display Output: This use case is initiated by the DBMS. It will display the account holders’ information on the screen after the processing has been done by the administrator.

Department of MCA ,MSRIT,Bangalore. 36

Page 37: Ooad Lab Programs

Object oriented analysis and design lab report

Flow of events:

Verify Account :

Pre-condition:The Account Holder should have a PIN number.

Normal Flow:1. Requested for the PIN number.2. Enters the PIN number. If invalid alternate flow 13. The Administrator checks with the Database if the requested PIN number

exists. If it is invalid go to Alternate Flow 2.4. If valid, it will ask the account holder to deposit money.

Alternate Flow 1: Requested pin number again.Alternate Flow 2:

1. Request the user to enter valid PIN. Go to Normal Flow 2.2. If again invalid PIN then come out of the transaction.

Post-Condition:The PIN number is validated and the user is requested to start the required

transaction.

Deposit Money:

Pre-Condition:The account is validated.

Normal Flow:1. Enter the cheque number.2. Enter the branch.3. Enter the Amount.4. If cheque is valid, balance is updated.5. If invalid, go to Alternate Flow 1.

Alternate Flow:1. Balance remains unchanged.

Post-Condition:The amount is deposited to the respective account type and balance is updated.

Calculate Interest:

Pre-Condition:The minimum balance should be there.

Normal Flow:1. Enter the account type.2. Enter the principle amount.3. Enter the rate of interest.4. Enter the number of years.5. If it is less than minimum balance go to Alternate Flow 1.6. Calculate the Simple Interest according to the formulae:

Department of MCA ,MSRIT,Bangalore. 37

Page 38: Ooad Lab Programs

Object oriented analysis and design lab report

SI = ( P * R * N ) / 100Amount = P + SI

Where P: Principle Amount

R: Rate Of Interest N: Number Of Years A: Amount SI: Simple Interest

a. The interest is computed and the balance is updated.

Alternate Flow:1. Display “ No minimum balance”Post-Condition:

The Simple Interest is calculated and balance is updated.

Display Output:

Normal Flow:1. The updated current balance is displayed on the screen by the

DBMS to the user.Alternate Flow:

No Alternate Flow.Post-Condition:

The Transaction is successful and completed.

CLASS DIAGRAM

Administrator

Account Holder NumberAccount Holder NameAmountRate of Interest

Validate User()Calculate Interest()Display Output()

Account Holder

NameAddressPhoneAccount NumberPin Number

Enter Pin()Deposit()

Deposit

PrincipleRate of InterestNumber of yearsSimple InterestAmount

Deposit()

Department of MCA ,MSRIT,Bangalore. 38

Page 39: Ooad Lab Programs

Object oriented analysis and design lab report

Class Documentation :

Account Holder - Account holder class will have the essentials details of the account holder. The details are Account holder’s name, address, phone number, the account number which will be an unique number for each account holder, Pin number. The pin number is known to the account holder.

Administrator - Administrator class will have the details of account holder number, Account holder name and the Rate of interest needed to calculate the Simple Interest . The account number is used by the administrator for verifying the account holder.

Deposit - Deposit is a class which will have the details of the principle amount of the account holder, Rate of Interest, the time in number of years. The Simple Interest is going to be added to the principle and will be known as the amount.

Department of MCA ,MSRIT,Bangalore. 39

Page 40: Ooad Lab Programs

Object oriented analysis and design lab report

Java code

import java.io.*;import java.lang.*;

class AccountHolder{

String name;int accno;float balance;

void GetDetails(){

try{BufferedReader BR = new BufferedReader( new

InputStreamReader(System.in));

System.out.println("Enter Name ... :");name = BR.readLine();

System.out.println("Entet Account No ... :");accno = Integer.parseInt(BR.readLine());

System.out.println("Enter Main Balance ... : ");balance = Float.parseFloat(BR.readLine());}catch(Exception e){

System.out.println(e);}

}

void ShowDetails(){

System.out.println(" Account Holder Name : " + name);System.out.println(" Account Number : " + accno);System.out.println(" Account Balance : " + balance);

}}

class Deposite extends AccountHolder{

float DepositeAmount;float Rate;float SimpleInterest;int Year;

Department of MCA ,MSRIT,Bangalore. 40

Page 41: Ooad Lab Programs

Object oriented analysis and design lab report

void CalculateInterest(){

try{BufferedReader BR = new BufferedReader( new

InputStreamReader(System.in));

System.out.println("Enter Amount To Be Deposited ... ");DepositeAmount = Float.parseFloat(BR.readLine());

System.out.println("Enter No. of Years ... ");Year = Integer.parseInt(BR.readLine());

System.out.println("Enter Rate of Interest ... ");Rate = Float.parseFloat(BR.readLine());

balance = balance + DepositeAmount;

System.out.println(" Account Balance after Deposit : " + balance);

SimpleInterest = ((balance * Rate * Year)/100);

balance = balance + SimpleInterest;}catch(Exception e){

System.out.println(e);}

}

void ShowAmount(){

System.out.println(" Deposited Amount : " + DepositeAmount);System.out.println(" Simple Interest : " + SimpleInterest);System.out.println(" Updated Balance : " + balance);

}}

class CalculateInterest{public static void main(String args[]){

Deposite D1 = new Deposite();D1.GetDetails();D1.ShowDetails();D1.CalculateInterest();D1.ShowAmount();

}}

Department of MCA ,MSRIT,Bangalore. 41

Page 42: Ooad Lab Programs

Object oriented analysis and design lab report

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 several customers can spend an account as a joint account. 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 persons, the value of users=5. If it is a single user account, users=1.Write the UML class diagram for account:

The account number is long type. Cust () is an array of length=users. If the users=5, cust () is of 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 Uname DOB ADD Phone no

Address

Object name

Street City State Country Pin code

Deposit:Principle p=No. of years n=Rate of interest=Account:Account object: a1A/c No:Customer object:No. of users:Deposit object: d1Sample Output:A/c No:Customer ID:First name:Last name:DOB:Address:Phones:

Department of MCA ,MSRIT,Bangalore. 42

CUSTOMER DEPOSITACCOUNT

Page 43: Ooad Lab Programs

Object oriented analysis and design lab report

Customer ID:First name:Last name:DOB:Address:Phones:

No of users:Deposit:Principle:Rate of interest:No of years:Simple interest:Amount:

Problem Statement:

In a bank customer opens a account and in that account he/she deposits money. Customers have several accounts. Several customers can use an account as joint account. The above two conditions should be differentiated and the number of users of

those account should be indicated. Write UML class diagram consisting customer class and address class. In account

class there is an attribute called user of integer type. This tells the number of users.

If the joint account is by 5 persons the value of users =5. If it is a single user account then user=1. Write UML class diagram for account. The account number is of long type Cust () is an array of length users. If user=5 then cust() is of length 5. Another attribute of account is an object of deposit class. Write UML diagram for deposit.

Requirements:

1 The bank client must be able to deposit amount into his/her account.2 Recorded transaction must include date, time, amount and account balance after

transaction.3 Customers can have more than one account.4 The bank application operates for single banking institutions only.5 Client’s deposits money called principle amount into the bank and specify the

amount to be deposited for number of years based on that the rate of interest is calculated.

6 The system must be able to get number of customers at any time.7 The system must provide security. 8 There are three types of accounts they are savings, current and joint.9 More than one customer can share account.

Department of MCA ,MSRIT,Bangalore. 43

Page 44: Ooad Lab Programs

Object oriented analysis and design lab report

IDENTIFICATION OF ACTORS:

Actors:1) Clerk2) BIS

ACTOR DOCUMENTATION:

Clerk:This actor is responsible for processing the client request, authentication and

carrying out the transactions of the client.

BIS: This actor is responsible for holding the details of various transaction of the client.

USE CASE DIAGRAM:

USE CASE DOCUMENTATION:(1)

USE CASE NAME : D EPOSIT MONEY

DESCRIPTION This use case is initiated by bank clerk Bank client deposits money (cash) at random time. Under the account type we have Joint, Saving and current

PRE-CONDITION Verification and validation of account number, user id authenticated by clerk through BIS.

Department of MCA ,MSRIT,Bangalore. 44

Page 45: Ooad Lab Programs

Object oriented analysis and design lab report

NORMAL FLOW 1.Enter account number 2.Valid account number 3.Enter customer id. 4.Valid customer id. 5.Enter amount for deposit (cash). ALTERNATIVE FLOW Not authenticated. POST CONDITION Update of transaction.

(2)

USE CASE NAME : INTEREST CALCULATIONDESCRIPTION This use case is initiated by bank clerk. It

calculates the simple interest and updates the balance amount.

PRE-CONDITION Verification and validation of account number, user id authenticated by clerk through BIS.

NORMAL FLOW Calculation of simple interest.ALTERNATIVE FLOW Not authenticated. POST CONDITION Update Balance.

CLASS DIAGRAM :

Analysis Phase:

Shared

AddressStreetCityStateCountryPincode

Display()

CustomerCustomer_idFirst_NameLast_NameDOBPhone_NoAddress

Display()

Contains

DepositPrincipleNo_Of_YerasRate_Of_Interest

Interest_Calculation()

AccountAcc_noAcc_TypeNo_Of_UsersStart_DateDepositCustomer

Deposit_Amt()GetNoOfUsers()

Has

Department of MCA ,MSRIT,Bangalore. 45

Page 46: Ooad Lab Programs

Object oriented analysis and design lab report

Design Phase:

AddressStreet : StringCity : StringState : StringCountry : StringPincode : Integer

Display()

CustomerCustomer_id : StringFirst_Name : StringLast_Name : StringDOB : IntegerPhone_No : IntegerAddress : Address Addr

Display()

Contains

DepositPrinciple : floatNo_Of_Yeras : IntegerRate_Of_Interest : Integer

Interest_Calculation()

AccountAcc_no : LongAcc_Type : StringNo_Of_Users : IntegerStart_Date : StringDeposit : Deposit DepCustomer : Customer Cust

Deposit_Amt()GetNoOfUsers()

Has

Shared

Class Diagram Description

Class Customer:

This class contains the customer’s personal details like customer identification number,

name of the account holder, his address and date of birth. It will display the customer’s

details on request.

Class Account:

This class contains the account details of the customer like account number, if it is a joint

account then the number of users, date of opening the account and the amount deposited.

This displays the number of users and the amount deposited on request.

Class Address :

This class contains the address details of the customer where is location is recorded as a

proof of existence. This displays the address details of the account holder on request.

Class Deposit :

This class contains the deposit details of the customer with respect to a particular account.

Here we calculate the simple interest based on the principal, number of years deposited

since the last time and interest, which is fixed by the bank. This displays the bank interest

calculated on a particular account.

Department of MCA ,MSRIT,Bangalore. 46

Page 47: Ooad Lab Programs

Object oriented analysis and design lab report

Problem No: 10

Consider the object college of mini project for the entire given specification in the

problem construct following UML diagrams.

Specification: In a college of CS there are computer laboratories and equipments.

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

1. Class Diagram

2. Object Diagram

3. Interaction Diagram

a) Sequence Diagram

b) Collaboration Diagram

4. Deployment Diagram

Requirements:

The system shall display the equipment details of the computer laboratory of college.

The maintenance person shall update the details of the laboratory equipments in college.

The user shall be allowed to view the details of equipments in college.Actors:

1. Lab User2. Maintenance Person3. Database

Actor Documentation:

1. Lab User: User is an actor who views the details of the laboratory equipments.

2. Maintenance person: Maintenance person is an actor who updates the information about the equipments.

3. Database: Database is an actor, which contains the details of laboratory equipments.

Department of MCA ,MSRIT,Bangalore. 47

Page 48: Ooad Lab Programs

Object oriented analysis and design lab report

Use Case Diagram:

Authentication

Maintenance person

User

Update

<<uses>>

Database

View details

Use Case Documentation:

Authenticate: The maintenance person initiates this Use case. The maintenance person enters the login id and password. If the login id and password are valid the maintenance person is allowed to update information and view the database.Flow of events:

1. Request ID 2. Request Password3. Enter ID4. Enter Password5. Verify ID invalid go to alternate flow6. Verify Password invalid go to alternate flow

Alternate Flow:1. Request ID 2. Request Password3. Enter ID4. Enter Password5. Verify ID

6. Verify Password Precondition: The maintenance person shall be provided with a login-id and password.Post condition: The valid user is allowed to update the information.

Department of MCA ,MSRIT,Bangalore. 48

Page 49: Ooad Lab Programs

Object oriented analysis and design lab report

Update: This Use case is initiated by the maintenance person. The maintenance person is allowed to update the database.Flow of events:

1. Request for details2. Enter name and description3. Update database

Precondition: The database has to be created.Post condition: The details has to be stored into the database.

View details : This Use case is initiated by general user. User is allowed to view the details of the lab.Flow of events:

1. Request lab details display form2. Show form

Precondition : The equipment details has to be present in the database.Post condition: The equipment details is displayed by the system

Sequence diagrams:

1. Sequence diagram for authentication:

Maintenance person : loginForm

Database

1: Enter id and password

2: Verify

3: Verification

4: Valid user

Department of MCA ,MSRIT,Bangalore. 49

Page 50: Ooad Lab Programs

Object oriented analysis and design lab report

2. Sequence diagram for Update:

Maintenance person

Database

3: verification

: maintenanceForm

1: Enter id & password2: Verify

4: Valid User

5: Request details

6: Enter details

7: Update details

3. Sequence diagram for View details:

User Database

3: Retrieve

: viewdetailsForm1: Request details

4: Send details

5: Display details

2: Check database

Department of MCA ,MSRIT,Bangalore. 50

Page 51: Ooad Lab Programs

Object oriented analysis and design lab report

Collaboration diagrams:

1. Collaboration diagram for Authentication:

User

Database

3: Retrieve

: viewdetailsForm

1: Request details

5: Display details

4: Send details

2: Check database

2. Collaboration diagram for Update:

Database

Maintenance person

3: verification

: maintenanceForm6: Enter details

1: Enter id & password

5: Request details

7: Update details2: Verify

4: Valid User

3. Collaboration diagram for View details:

User

Database

3: Retrieve

: viewdetailsForm

1: Request details

5: Display details

4: Send details

2: Check database

Department of MCA ,MSRIT,Bangalore. 51

Page 52: Ooad Lab Programs

Object oriented analysis and design lab report

Class diagram:

TerminalTerminal-configuration

Get_configuration()

ServerServer-configuration

Get_configuration()

PeripheralsMakeType of device

Get_type_of_device()

EquipmentEquipment-idPurchase-dateWarranty

Get_details()

CollegeNameAddress

Display()

LabLab-id

Get_equipment_details()

SoftwareLicenseNo of copiesValidity

check_validity()

Class diagram documentation:

The various classes involved here are:1. Software class2. Lab class3. Peripherals class4. Equipments class

Software Class: The attributes here are license, No of copies and validity.Lab Class: The attributes here are Lab-id, which is meant for identification of labs.Peripherals Class: The attributes here are Make and Type.Equipment Class: The attributes here are Equipment-Id, Purchase-date and Warranty.

Deployment diagram:

Database Server

Client Machine

LAN

Deployment diagram documentation:

Database will be stored in the server and will be accessed by the user through LAN.

Department of MCA ,MSRIT,Bangalore. 52

Page 53: Ooad Lab Programs

Object oriented analysis and design lab report

Program11:

C Library Information System

Problem Statement:

A Library lends books and magazines to member, who is registered in the system. Also it handles the purchase of new titles for the Library. Popular titles are bought into multiples copies. Old books and magazines are removed when they are out or 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 tiles, members, loans and reservation in the system.

Requirement Specification

The Library System offers the following Services: Issuing of Books and Magazines to member who are registered in the system. It handles the purchase of new titles for library. Popular titles are bought in

multiple copies. Old books and magazines are removed when they are out of date or in poor

condition. If a member asks for a book/magazines then

o The book is issued if availableo Otherwise, it is reserved for that member so that he can get the book when

book is available. It shall provide the loan for purchasing book for student It shall provide a way to create, replace and delete information about book titles,

member, loans and reservation in the system.

Use-case Documentation

1) Notify: The librarian initiates this use case when any member returns the book and checking if the book is already reserved.

Precondition: The member should return Book.Normal Flow: Build message for member who reserved the book.Post Condition: Send message to respective member who reserved the book.

2) Borrow Book: Initiated by librarian when any member wants to borrow the desired book. If the book is available, the book is issued.

Precondition: Member should be valid member of library.Normal Flow: Selected book will be issued to the member.Alternative Flow: If book is not available then reserved book use case should be initiate.Post Condition: Update the catalogue.

Department of MCA ,MSRIT,Bangalore. 53

Page 54: Ooad Lab Programs

Object oriented analysis and design lab report

3) Reserve Book: Initiated by librarian when the requested book is not available in the library at that moment. The book is reserved for the future and issued to the person when it is available.

Precondition: Initiated only when book is not available.Normal Flow: It reserved the book if requested.Post Condition : Mention the entry in catalogue for reservation.

4) Return Books: Invoked by the librarian when a member returns the book.

Precondition: Member should be valid member of library.Normal Flow: Librarian enters bookid and system checks for return date of the book.Alternative Flow: System checks for return date and if it returned late fine message will be displayed.Post Condition: check the status of reservation.

5) Check library card: The borrow and return use-cases use it to check the validity of the user-card.

Normal Flow: Enter the memberid.Alternative Flow: system will going to validate the member and if member is not valid message will be supplied.Post Condition: Then depending upon the transaction (i.e. borrow or return book) system will initiate corresponding operation.

6) Add Books: The purchase book use-case when new books invoke it or magazines are added to the library.

Precondition: Not available or more copies are required.Normal Flow: Enter bookid and no of copies.Post Condition: Update the information in catalogue.

7) Remove Book: Initiated by the Library Inventory Manager when old and damaged books are removed from the library.

Precondition: Books are in the outdated condition.Normal Flow: Remove the book from library.Post Condition: Update the catalogue.

Department of MCA ,MSRIT,Bangalore. 54

Page 55: Ooad Lab Programs

Object oriented analysis and design lab report

Remove Book

Notify

Return Book

Check Library Card

<<Uses>>

LIBRARIAN

Borrow Books & Magzines

<<Uses>>

Reserve Books

<<extend>>

USE CASE DIAGRAM FOR LIBRARY

LIBRARY INVENT...

Add Book

Actor Documentation

1) Librarian: The Librarian is a person who is responsible for maintaining, issuing/renewal and reserving of the books. This person also verifies the user’s library card before issuing, renewing, reserving or accepting a book when returned.

2) Library Inventory Manager: He/she is responsible for maintaining the library database by adding and removing the books and their related details as required. He/she is also responsible for placing orders with the supplier and updating the database according to the corresponding changes made.

Department of MCA ,MSRIT,Bangalore. 55

Page 56: Ooad Lab Programs

Object oriented analysis and design lab report

Lib Inventory Manager

Lib Info System

Sequence diagram for removing book

1: Query For Outdated / Damaged Books

2: Check for damage

3: display damaged book_id

4: Delete

Lib Inventory Manager

Lib Info System

Collobration diagram for removing the book

2: Check for damage4: Delete

1: Query For Outdated / Damaged Books

3: display damaged book_id

Department of MCA ,MSRIT,Bangalore. 56

Page 57: Ooad Lab Programs

Object oriented analysis and design lab report

Librarian Lib Info System

SEQUENCE DIAGRAM FOR BORROWING BOOKS

1: Verify Id

2: Get File

3: Valid User

4: Get book_id

5: Update

6: Issue Book

Librarian

Lib Info System

2: Get File5: Update

Collobration diagram for borrowing the book

1: Verify Id4: Get book_id

3: Valid User6: Issue Book

Department of MCA ,MSRIT,Bangalore. 57

Page 58: Ooad Lab Programs

Object oriented analysis and design lab report

Librarian Lib Info System

1: Verify Id

DIAGRAM FOR RESERVE BOOKS

2: Get File

3: Valid User

4: Get book_id

5: Check for availability

6: Display Unavailable

7: request for reserve book

8: Reserve

Librarian

Lib Info System

2: Get File5: Check for availability

COLLOBRATION DIAGRAM FOR RESERVE

8: Reserve

1: Verify Id4: Get book_id

7: request for reserve book

3: Valid User6: Display Unavailable

Department of MCA ,MSRIT,Bangalore. 58

Page 59: Ooad Lab Programs

Object oriented analysis and design lab report

Librarian Lib Info System

Sequence diagram for return books /Notify

1: Verify Id

2: Get File

3: Valid User

4: Enter book_id

5: Check for return date

6: Display fine(late return)

7: Check for reservation

8: Notify if reserve

Librarian

Lib Info System

2: Get File5: Check for return date

COLLOBRATION DIAGRAM FOR RETURNING BOOKS

7: Check for reservation

1: Verify Id4: Enter book_id

3: Valid User6: Display fine(late return)

8: Notify if reserve

Department of MCA ,MSRIT,Bangalore. 59

Page 60: Ooad Lab Programs

Object oriented analysis and design lab report

Activity diagram for library

Verify Id

Enter book_id

Issue Book and Update

[ Borrow book ]

Book Available

[ Yes ]

Not a Valid User

Reserve Book

[ No ]

[ invalid ][ Valid Member ]

Book_id[ Return book ]

Update &check for fine

Check for reserve

Class Diagram

BorrowLast_date

Issue()Display()Search()Reserve()

MemberMember_idNameAddressNo_of_book

Add_member()Remove()Display()Search()Update()

Return

Update()Check()Reserve()

BookIsbn

Condition()

MagazinesType

Add_Type()

CatalogueIdPriceAuthorPublisher

Add()Delete()Search()Display()

TransactionBook_idMember_id

Get_Bookid()Get_memberid()Get_Permission()

hasparticipates

Department of MCA ,MSRIT,Bangalore. 60

Page 61: Ooad Lab Programs

Object oriented analysis and design lab report

Class Documentation

1) Catalogue: It is main class contains all details about books and magazines and made up of two sub class Book and Magazines i.e. Aggregation relationship

2) Book: It is sub class of catalogue it uses the method such as Add(),Delete(),Search(),Display() of catalogue class and it also have one attribute Isbn and contains one method Condition() which show the condition of book for removing purpose.

3) Magazines: Is is also sub class of catalogue it also uses all the method of catalogue class and contains one attributes Type which describes the type of magazines.

4) Transaction: Its main class contains the inheritance relationship with Borrow and Return book.

5) Borrow Book: Contains details about the borrow book that is which member Borrow particular book and its return date.

6) Member: Contains all the information about member such as name,address,The no. of book particular member has etc.

Component Diagram

Transaction Member

Catalogue

Transaction: This Component consists of Borrow, Return class.

Member: This component consists Member class

Catalogue: This component consists of Book and Magazines Class.

Department of MCA ,MSRIT,Bangalore. 61

Page 62: Ooad Lab Programs

Object oriented analysis and design lab report

Program-12:

Develop the product using java programming language. Write UML

diagram for Railway Reservation System.

Requirement specification

The Automated Railway Reservation System offers the following services:

It is a software used by Railway reservation staff.

It shall provide train schedules and information

It shall provide availability of seats on given dates and given train names

To provide information about category (classes) of tickets like A/C, I class ,II

class, II class sleeper coach

Customers/passenger to fill the reservation form manually and give it to the

concerned railway staff.

After processing the customer/passenger information, the staff will verify

availability of the tickets. If it is available the customer/passenger has to pay the

ticket amount by cash to the railway staff. After the amount is paid the staff issues

the ticket to the passenger. Here we assume that no Waiting list ,RAC, tathkal

tickets are issued , Cancellation of tickets are also not available.

Updating information and availability of tickets taken care by by the railway staff

Use case diagram:

Railway Reservation System

Database

Railway Reservation staff

Processing Reservation form

issuing of tickets

Train Information

updating information and display availability of tickets

<<uses>>

<<extends>>

Department of MCA ,MSRIT,Bangalore. 62

Page 63: Ooad Lab Programs

Object oriented analysis and design lab report

Actors:

Railway Reservation Staff

Database

Description of Actors:

Railway Reservation Staff: He /she is responsible for processing the passenger’s request like checking the

availability of trains, booking the tickets and issuing of tickets.

Database: It is used to store, access and keep the updated records of reservation and

information about passenger, and trains. Database keeps track of the seats availability of respective trains on respective dates.

Use Case Description

1. Train Information: Description of use case:

The railway staff enters train information like train no., train name, date of journey, source and destination station. It checks the source and destination of trains and timings of train. Normal flow of events:

1. Enter the source station 2. Enter the destination station3. Enter the Train no.4. Enter the Train name.

Post condition: select the train to journey.

2. Availability Of Ticket:

Description of use case:The staff initiates this use case. For this the passenger is requested to fill a

prescribed form containing details of train no., train name, date of journey, source and destination station, class, then it check if the required seat is available or not. Pre condition: The customer will fill the required form and give it to the concerned staff.Normal flow of events:

1. Enter the source station. 2. Enter the destination station. 3. Enter the class of coach. 4. Enter the date of journey. 5.Enter the train no. 6.Enter the train name

7. If the reservation is available, display the details.Otherwise go to Alternative flow1.

Alternative Flow 1: Display that the reservation is not available.

Department of MCA ,MSRIT,Bangalore. 63

Page 64: Ooad Lab Programs

Object oriented analysis and design lab report

3. Processing Reservation Information: Description of use case:

The passenger is required to enter the train no., train name, date of journey, source and destination station, class, and no. Of seats, name, age, sex, address. Fill the required information of ticket along with personal information.Pre-condition: Seats should be available.Normal flow of event:

1. Enter the train name and train no. 2. Enter the source station. 3. Enter the destination station. 4. Enter the date of journey. 5. Enter the class of coach.

6 . Enter the Name.7 . Enter the Age.8 . Enter the Sex

9. Enter the address 10.Verify the details. If valid details pay the required amount in cash otherwise Alternative flow 1

Alternative Flow 1: Display the details to re-enter the missed details.Post-condition: The customer will be issued the ticket.

4. Issuing ticket:

Description of use case:

This is an extended use case of processing of reservation information. After the passenger details are correct the ticket will be given printed form Pre-condition: Amount must be paid in cash to railway staff

Normal flow of event:

1. Check the details of passenger.2. Give print message to the printer. 3. The ticket is issued.4. Database is updated.

Post Condition: The ticket is issued and is collected by the passenger.

Department of MCA ,MSRIT,Bangalore. 64

Page 65: Ooad Lab Programs

Object oriented analysis and design lab report

Sequence diagram of train information

Collaboration diagram of train information

railway staff

form

database

printer

6: process the info

1: enter the source station2: enter the destination station

3: enter the train no.4: enter the train name

5: submit the details

7: display the train info

Activity diagram of train information

Department of MCA ,MSRIT,Bangalore. 65

Page 66: Ooad Lab Programs

Object oriented analysis and design lab report

enter the source station

enter the destination station

enter the train no.

enter the train name

incorrect info

display train information

correct info

Department of MCA ,MSRIT,Bangalore. 66

Page 67: Ooad Lab Programs

Object oriented analysis and design lab report

Sequence diagram of availability of ticket

railway staff form database printer

1: enter the source station

2: enter the destination station

3: enter the class of coach

4: enter the date of journey

5: enter the train no.

6: enter the train name

7: submit the info

8: process the info

9: display the availability

Department of MCA ,MSRIT,Bangalore. 67

Page 68: Ooad Lab Programs

Object oriented analysis and design lab report

Collaboration diagram of availability of ticket

railway staff

form

database printer

1: enter the source station2: enter the destination station

3: enter the class of coach4: enter the date of journey

5: enter the train no. 6: enter the train name

7: submit the info

8: process the info9: display the availability

Department of MCA ,MSRIT,Bangalore. 68

Page 69: Ooad Lab Programs

Object oriented analysis and design lab report

Activity diagram of availability of tickets

enter the source station

enter the destination station

enter class of coach

enter the date of journey

enter the train no.

enter the train name

display available

reservation available

display not available

reservation not available

Department of MCA ,MSRIT,Bangalore. 69

Page 70: Ooad Lab Programs

Object oriented analysis and design lab report

Sequence diagram of processing reservation for

railway staff form database printer

1: enter the train no.

2: enter the train name

3: enter the source station

4: enter the destination station

5: enter the date of journey

6: enter the class of coach

7: enter the name

8: enter the age

9: enter the sex

10: enter the address

11: submit the info

12: process the info

13: display the amount to be paid

Department of MCA ,MSRIT,Bangalore. 70

Page 71: Ooad Lab Programs

Object oriented analysis and design lab report

Collaboration diagram of processing reservation form

railway staff

form

database

printer

1: enter the train no.2: enter the train name

3: enter the source station4: enter the destination station

5: enter the date of journey6: enter the class of coach

7: enter the name8: enter the age9: enter the sex

10: enter the address

11: submit the info12: process the info

13: display the amount to be paid

Department of MCA ,MSRIT,Bangalore. 71

Page 72: Ooad Lab Programs

Object oriented analysis and design lab report

Sequence diagram of issuing ticket

railway staff form database printer

1: enter the passenger details

2: submit the form

3: check the passenger details

4: display invalid details

5: reenter the details

6: submit the form

7: process the info

8: print the ticket

9: update the database

Department of MCA ,MSRIT,Bangalore. 72

Page 73: Ooad Lab Programs

Object oriented analysis and design lab report

Collaboration diagram of issuing ticket

railway staff

form

database printer

1: enter the passenger details

2: submit the form

3: check the passenger details4: display invalid details

5: reenter the details

6: submit the form

7: process the info

8: print the ticket

9: update the database

Department of MCA ,MSRIT,Bangalore. 73

Page 74: Ooad Lab Programs

Object oriented analysis and design lab report

Activity diagram of issuing ticket

enter the train no.

enter the source station

enter the destination station

enter the date of journey

enter the class of coach

enter the no. of passengers

enter the train name

enter name

enter age

enter sex

enter address

print ticket

incorrect details

Department of MCA ,MSRIT,Bangalore. 74

Page 75: Ooad Lab Programs

Object oriented analysis and design lab report

Class diagram:

Formsource_stationdestination_stationdate_of_journeyclass_of_coachno_of_passengers

get_passenger_detail()get_train_detail()

PassengerNameagesexaddress

Ticketticket_nodeparture_timeamount

calculate_fare()print_ticket()

traintrain_notrain_name

Department of MCA ,MSRIT,Bangalore. 75

Page 76: Ooad Lab Programs

Object oriented analysis and design lab report

Java code

import java.io.*;class Passenger{

String name;int age;String sex;String Address;

}class Train{

int Train_no;String Train_name;

}class Form{

Passenger pr =new Passenger();Train tr= new Train();String Source_Station;String Destination_Station;String Date_of_journey;int No_of_pass;String Class_of_coach;int i;

void get_pass_details(){ try { BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

System.out.println("No_of_pass:");No_of_pass=Integer.parseInt(br.readLine());System.out.println("Name:");pr.name=br.readLine();System.out.println("Age:");pr.age=Integer.parseInt(br.readLine());System.out.println("Sex:");pr.sex=br.readLine();System.out.println("Address:");pr.Address=br.readLine();get_train_details();}catch(Exception e) {}

}

void get_train_details()

Department of MCA ,MSRIT,Bangalore. 76

Page 77: Ooad Lab Programs

Object oriented analysis and design lab report

{try

{ BufferedReader br=new BufferedReader(new

InputStreamReader(System.in));System.out.println("Train Number:");tr.Train_no=Integer.parseInt(br.readLine());System.out.println("Train Name:");tr.Train_name=br.readLine();System.out.println("Source_Station:");Source_Station=br.readLine();System.out.println("Destination_Station:");Destination_Station=br.readLine();System.out.println("Date_of_journey:");Date_of_journey=br.readLine();System.out.println("Class_of_coach:");Class_of_coach=br.readLine();

}catch(Exception e) {}

}

}

class Ticket extends Form{

Train tr = new Train();int ticket_no;String Source_Station;String Destination_Station;String Departure_Time;int amount;int calc_fare(){ return 0;}

void print_ticket(){

ticket_no=0;ticket_no++;try{

System.out.println(" ");System.out.println("-------------------------------------------------- ");

System.out.println("Train Number : "+tr.Train_no);System.out.println("Train Name : "+tr.Train_name);System.out.println("Ticket Number : "+ticket_no);

Department of MCA ,MSRIT,Bangalore. 77

Page 78: Ooad Lab Programs

Object oriented analysis and design lab report

System.out.print("Source Station : "+Source_Station);System.out.print("\t To \t");System.out.println("Destination_Station : "+Destination_Station);System.out.println("Date_of_journey : "+Date_of_journey);System.out.println("No_of_pass : "+No_of_pass);System.out.println("Amount : ******");System.out.println("---------------------------------------------------");System.out.println(" ");

}catch(Exception e){}

} }

class railway{

public static void main(String args[]){

try{

Ticket tk= new Ticket(); tk.get_pass_details(); tk.print_ticket();

}catch(Exception e){

System.out.println("Error");}

}}

Department of MCA ,MSRIT,Bangalore. 78