Académique Documents
Professionnel Documents
Culture Documents
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.
For this we define a GUI class called Ruled derived from frame class of javax.swing library.
Javax.swing.Jfr
Super class
ame
Name of the GUI component: ruled class hierarchy :subclass of JFrame class of
Javax.swing library.
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
CS&E. 1
5th Semester OOAD Lab.
Horizontal
Draw Line Set Dimension (from Logical View)
Horizontal()
paint()
main()
<<derive>> <<extend>> jblnit()
Programmer
<<derive>>
Grid Create & Handle Window
Sequence Diagram:
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;
CS&E. 3
5th Semester OOAD Lab.
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
<<derive>> <<extend>>
Programmer
<<derive>>
Grid Create & Handle Window
Class Diagram:
Crossed
Crossed()
paint()
main()
jbInit()
CS&E. 4
5th Semester OOAD Lab.
Sequence Diagram:
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.
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.
<<extend>>
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:
Sequence Diagram:
1: Identify()
2: Inform()
3: Inform()
4: Send Recomendation()
6: Conduct Interview()
7: Select Candidates( )
CS&E. 9
5th Semester OOAD Lab.
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
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
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
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.
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:
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:
Display Result
Actor:
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
CS&E. 17
5th Semester OOAD Lab.
Java Program:
class Subject
{
String code;
String title;
int passingmin;
int max;
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");
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.
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.
Customer Television
Actors:
Use Cases:
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:
Sequence Diagram:
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));
}
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.
CS&E. 23
5th Semester OOAD Lab.
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 ()
import java.io.*;
import java.util.*;
CS&E. 24
5th Semester OOAD Lab.
CS&E. 25
5th Semester OOAD Lab.
In a bank the customer opens an account and in that account he/she deposits money. So
the entities are:
A customer can have several accounts and an account can be spent as a joint account by
several customers. In the customer class, the address of the customer is constructed as an object
of a class called Address. Write the UML class diagram consisting Customer class and Address
class. In the account class, there is an attribute called users. This is an integer attribute. It tells
number of users of the account. If the account is a joint account by 5 persons, the value of
users=5. If it is a single user account, users =1.
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:
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.
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:
return info
CS&E. 31
5th Semester OOAD Lab.
b. Collaboration diagram:
5: return info
11: return result
5. Deployment diagram.
college
College Information
System
CS&E. 32
5th Semester OOAD Lab.
For the above problem specification devise the following UML diagrams:
CS&E. 33
5th Semester OOAD Lab.
Lends
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.
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()
CS&E. 36
5th Semester OOAD Lab.
3. Sequence diagram:
If book available
CS&E. 37
5th Semester OOAD Lab.
checks again
book available
CS&E. 38
5th Semester OOAD Lab.
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
D a tab as e
CS&E. 39
5th Semester OOAD Lab.
Databas
e
CS&E. 40
5th Semester OOAD Lab.
6. Activity diagram:
Book available?
yes
no
Member reserves
book/magazines
CS&E. 41
5th Semester OOAD Lab.
7. Component diagram:
Dat abase
Librarian Member
8. Deployment diagram:
Library
CS&E. 42
5th Semester OOAD Lab.
Write the UML diagram for Railway Reservation System Develop the product using the
java program.
<<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.
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.
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