Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 50

COMPUTER LABORATORY MANUAL

Software Design and Architecture


(SEN 321 L)
Version 2.0

Group Member: BSSE 4B

Muhammad Afrasiyab khattak Khan (087)

DEPARTMENT OF SOFTWARE ENGINEERING (DSE)


FOUNDATION UNIVERSITY RAWALPINDI CAMPUS (FURC)
www.fui.edu.pk
http://www.fui.edu.pk/FURC/
PREFACE
This Lab Manual has been specially designed with the idea of improving and enhancing the problem-solving
skills of students through consistent practice and creativity. There are 14 experiments in this Lab Manual,
which cover all the topics taught in the BCSE core course Software Design & Architecture. The questions
have been carefully devised with the idea of keeping the students interested as well as motivated to complete

1 SDA Lab Manual


the designated tasks. There are tasks included in each lab activity. These tasks are intended to refine a
student’s advanced level skills.

PREPARED BY
Lab manual is prepared by Assistant Professor Umar Mahmud under the supervision of Head of Department
Professor Dr. Muhammad Shaheen.

GENERAL INSTRUCTIONS
a. Students are required to maintain the lab manual with them till the end of the semester.
b. All readings, answers to questions and illustrations must be solved on the place provided. If more space is
required, then additional sheets may be attached. You may add screen print to the report by using the
‘Print Screen’ command on your keyboard to get a snapshot of the displayed output.
c. It is the responsibility of the student to have the manual graded before deadlines as given by the instructor.
d. Loss of manual will result in re submission of the complete manual.
e. Students are required to go through the experiment before coming to the lab session.
f. Students must bring the manual in each lab.
g. Keep the manual neat clean and presentable.
h. Plagiarism is strictly forbidden. No credit will be given if a lab session is plagiarised and no re-submission
will be entertained.
i. Marks will be deducted for late submission.
j. You need to submit the report even if you have demonstrated the exercises to the lab instructor or shown
them the lab report during the lab session.

VERSION HISTORY
Date Update By Details
July 2018 Umar Mahmud Version 1.0. Initial draft prepared and experiments outlined.
Jan 2020 Umar Mahmud Version 2.0. Experiments are revised and questions are
reviewed. Experiments are revised for MS Visio 2106
Aug 2023 Dr. Maryam Kausar Version 3.0 Details were added and sequence of the manual
was updated. Project was added.

MARKS

LAB Date Lab Title Max. Marks Instructor


# Conducted Marks Obtained Sign

2 SDA Lab Manual


PROJECT

1 INTRODUCTION TO MS VISIO 10
2 USE CASE DIAGRAMS 10

3 SYSTEM SEQUENCE DIAGRAM 10

4 DOMAIN MODEL 10

5 CLASS DIAGRAM 10

7 ACTIVITY DIAGRAM 10

9 MODEL VIEW CONTROLLER 10


(MVC)
10 MVC IMPLEMENTATION 10

11 DESIGN PATTERNS 10

12 FACTORY PATTERN 10

13 OBSERVER PATTERN 10
14 MODULAR DESIGN 10

GRAND TOTAL

LIST OF EXPERIMENTS

3 SDA Lab Manual


EXPERIMENT 1 – INTRODUCTION TO MS VISIO......................................................................................5
EXPERIMENT 2 – USE CASE DIAGRAMS.................................................................................................11
EXPERIMENT 3 – SYSTEM SEQUENCE DIAGRAM.................................................................................19
EXPERIMENT 4 – DOMAIN MODEL...........................................................................................................21
EXPERIMENT 5 – CLASS DIAGRAM..........................................................................................................24
EXPERIMENT 7 – ACTIVITY DIAGRAM....................................................................................................26
EXPERIMENT 9 – MODEL VIEW CONTROLLER (MVC).........................................................................27
EXPERIMENT 10 – MVC IMPLEMENTATION...........................................................................................31
EXPERIMENT 11 – DESIGN PATTERNS ......................................................................................................
35 ...........................................................................................................................................................................
EXPERIMENT 11 – FACTORY PATTERN....................................................................................................41
EXPERIMENT 13 – OBSERVER PATTERN..................................................................................................43
EXPERIMENT 14 – MODULAR DESIGN.....................................................................................................44

4 SDA Lab Manual


EXPERIMENT 1 – INTRODUCTION TO MS VISIO

EXERCISE 1.1 [4] Cerate a program for language of your choice. The program does the
following: -
• First it asks user to enter the code of the item purchased by a customer.
• If item code is valid, the description and price for that code is displayed on the screen.
• If item code is invalid, message is displayed “Item Code doesn’t exist”.
• Then it asks for the quantity of the item code entered. If quantity is less than zero, it prompts user to
enter quantity greater than zero.
• It displays the subtotal thereafter.
• Moreover, it keeps on accepting item codes until ‘0’ is pressed.
• Consequently, it displays the total amount due.
• Then, it asks the user to tender the amount of cash of the customer. It should not accept amount of
cash less than the amount due.
• Finally, it displays the change. Show
code and outcome screens here: -
CODE:
package javaapplication144;
import java.util.Scanner;
class shop
{
boolean check(int code)
{
return true;
}
void buy()
{
Scanner scan = new Scanner(System.in);
shop ob = new shop();
System.out.println("Enter the code of item");
int code = scan.nextInt();
if(ob.check(code))
{
System.out.println("detail of product");
System.out.println("Enter item quantity");
int quantity=scan.nextInt();
if(quantity<=0)
{
System.out.println("enter quantity greater then 0");
}
else
{
System.out.println("subtotal of items");
}

5 Experiment 1 – Introduction to MS Visio


System.out.println("Due Amount");
float totamount=110000;
System.out.println("tender each cutomer amount");
float amount = scan.nextFloat();
if(amount < totamount)
{
System.out.println("cash amount is less then total amount");
}
else
{
System.out.println("show changes");
System.out.println("press 0 to continue");
int s = scan.nextInt();
if(s!=0)
{
System.out.println("Exit");
}
else
{
ob.buy();
}
}
}
else
{
System.out.println("code is invalid");
}

}
}
public class JavaApplication144
{

public static void main(String[] args)


{
shop ob = new shop();
ob.buy();
}

6 Experiment 1 – Introduction to MS Visio


OUTPUT

7 Experiment 1 – Introduction to MS Visio


EXERCISE

1.2 [6]
Draw and submit a flowchart for a cashier program.

8 Experiment 1 – Introduction to MS Visio


RESOURCES
http://office.microsoft.com/en-001/visio-help/a-beginner-s-guide-to-visio-HA102749363.aspx
https://www.youtube.com/watch?v=b09dKHvu4-4
EXPERIMENT 2 – USE CASE DIAGRAMS

TASK 2.1: CASE STUDY


Harriet's require a new point of sale and stock control system for their many stores throughout the UK to
replace their ageing mini based systems.
A sales assistant will be able to process an order by entering product numbers and required quantities into the
system. The system will display a description, price and available stock. In-stock products will normally be
collected immediately by the customer from the store but may be selected for delivery to the customer's
home address for which there will be a charge. If stock is not available, the sales assistant will be able to
create a backorder for the product from a regional warehouse. The products will then either be delivered
direct from the regional warehouse to the customer's home address or to the store for collection by the
customer. The system will allow products to be paid for by cash or credit card. Credit card transactions will
be validated via an online card transaction system. The system will produce a receipt. Order details for in-
stock products will be printed in the warehouse including the bin reference, quantity, product number and
description. These will be collected by the sales assistant and given to the customer. The sales assistant will
be able to make refunds, provided a valid receipt is produced. The sales assistant will also be able to check
stock and pricing without creating an order and progress orders that have been created for delivery.
The store manager will be able at any time to print a summary report of sales in the store for a given period,
including assignment of sales to sales assistants in order to calculate weekly sales bonuses.
The stock manager will be able to monitor stock levels and weekly run-rates in order to set minimum stock
levels and requisition products which fall below the minimum stock levels or for which demand is
anticipated. When the stock arrives, it will be booked in by the warehouse person. Stock that has been
backordered for collection from the store is held in a separate area and the store manager advised of its
arrival.
The catalogue of available products will be maintained remotely by marketing from head office. Marketing
will also be able to access sales information from each store system.
2.1 [2]
Enlist all the possible Actors in the above scenario. Also write descriptions of each in table.
• Sale assistant
• Customer
• Delivery boy
• Store manager

9 Experiment 2 – Use Case Diagrams


EXERCISE

• Stock manager
• Ware house person
• Online transaction system

Description of Actors:
1. Sale Assistant:
sales assistant will be able to process an order by entering product numbers and required quantities into
the system. If stock is not available, the sales assistant will be able to create a backorder for the product
from a regional warehouse.
2. Customer:
Customer will be able to order items from the store. In-stock products will normally be collected
immediately by the customer from the store.
3. Delivery boy:
The products will then either be delivered direct from the regional warehouse to the customer's home
address by delivery boy or to the store for collection by the customer.
4. Store manager:
The store manager will be able at any time to print a summary report of sales in the store for a given
period, including assignment of sales to sales assistants in order to calculate weekly sales bonuses.
5. Stock manager:
The stock manager will be able to monitor stock levels and weekly run-rates in order to set minimum
stock levels and requisition products which fall below the minimum stock levels or for which demand
is anticipated.
6. Ware house person:
When the stock arrives, it will be booked in by the warehouse person.
7. Online transaction system:
Credit card transactions will be validated via an online card transaction system.

EXERCISE 2.2 [2]


Enlist all the possible Use Cases in the above scenario. Also write description in a single table.

Use cases of Sale Assistant:


1. Process order:
A sales assistant will be able to process an order by entering product numbers and required quantities into the
system.
2. Create back order:
If stock is not available, the sales assistant will be able to create a backorder for the product from a regional
warehouse.
3. Provide order details to customer:
Order details for in-stock products will be printed in the warehouse including the bin reference, quantity, product
number and description. These will be collected by the sales assistant and given to the customer.
4. Make refunds:
The sales assistant will be able to make refunds

5. Provide receipt:
The sale assistant will provide valid receipt to customer.

10 Experiment 2 – Use Case Diagrams


6. Check stock and pricing:
The sales assistant will also be able to check stock and pricing without creating an order and progress
orders that have been created for delivery.

Use cases of Customer:


1. Collect products:
In-stock products will normally be collected immediately by the customer from the store.
2. Billing:
Give payment.
3. Search product

Use cases of Delivery Boy:


1. Deliver items:
The products will then either be delivered direct from the regional warehouse to the customer's home address by
delivery boy. OR The products will then either be delivered to the store for collection by the customer.
Use cases of Store Manager:
The store manager will be able at any time to print a summary report of sales in the store for a given
period, including assignment of sales to sales assistants in order to calculate weekly sales bonuses.
Use cases of Stock Manager:
The stock manager will be able to monitor stock levels and weekly run-rates in order to set minimum
stock levels and requisition products which fall below the minimum stock levels or for which demand
is anticipated.
Use cases of ware house person:
When the stock arrives, it will be booked in by the warehouse person. The catalogue of available
products will be maintained remotely by warehouse person from head office. Warehouse person will
also be able to access sales information from each store system.
Use cases of Online transaction system:
Credit card transactions will be validated via an online card transaction system.

2.3 [4]
Draw a use-case diagram of the above requirement specifications.

11 Experiment 2 – Use Case Diagrams


EXERCISE

12 Experiment 2 – Use Case Diagrams


ID UC-5

Title Give payment

Description The customer can give payment through cash or card

Primary Actor Customer

Precondition Customer must have bought some item

Postcondition Customer will successfully get his product

Main Success Customer System

EXERCISE 2.4 [2] Write use case description table for each use case. A sample is given below: -
ID UC-4

Title Search product

Description The customer can search for clothes into the system. Customers can search by size,
price and colour.

Primary Actor Customer

Precondition Customer must be login into the system.

Postcondition Customer will successfully find his product

Main Success Customer System


Scenario
1. Customer select search 3. System will provide searched
option products to the Customer.
2. Customer can search by size,
price and gender.

Alternate flow 3a. There is trouble in internet connection. 3b.


No search option provided.

13 Experiment 2 – Use Case Diagrams


Scenario 1. Customer select payment 3. System will provide selected option
option. to the Customer.

Alternate flow 3a. There is trouble in internet .


connection

ID UC-6

Title Deliver items

Description The delivery boy will deleiver item to customer address or the store

Primary Actor Delivery boy

Precondition Delivery boy have address to be delivered on to

Postcondition Delivery boy will correctly deliver item to that address

Main Success Delivery boy System


Scenario
1. He will check which place 3. System will provide all the
to deliver addresses where to deliver
the items

Alternate flow 3a. There is trouble in internet connection.


3b.address provided is invalid

14 Experiment 2 – Use Case Diagrams


ID UC-7

Title Create back order

Description The sale assistant can create back order for currently un available products

Primary Actor Sale assistant

Precondition Item should be present in market

Postcondition Sale assistant will get the item from another branch later successfully

Main Success Sale assistant System


Scenario
1. Sale assistant select 3. System will allow to create the back
items to create back order
order of

Alternate flow 3a. There is trouble in internet connection.


3b.no back order available

ID UC-8

15 Experiment 2 – Use Case Diagrams


Title Provide order details to customer

Description The sale assistant will provide all details name, id etc of product to customer

Primary Actor Sale assistant

Precondition Customer have bought some item

Postcondition Sale assistant will provide order details to customer

Main Success Sale assistant System


Scenario
1. sale assistant will have all the 3. System will provide bought product
details of item purchased by details to customer
customer

Alternate flow 3a. There is trouble in internet connection.

WEB RESOURCES
http://en.wikipedia.org/wiki/Use_Case_Diagram
http://office.microsoft.com/en-ca/visio-help/create-a-uml-use-case-diagram-HP081550218.aspx
http://www.math-cs.gordon.edu/courses/cs211/ATMExample/UseCases.html

EXPERIMENT 3 – SYSTEM SEQUENCE DIAGRAM

16 Experiment 2 – Use Case Diagrams


TASK 3.1: CASE STUDY
Harriet's require a new point of sale and stock control system for their many stores throughout the UK to
replace their ageing mini based systems.
A sales assistant will be able to process an order by entering product numbers and required quantities into
the system. The system will display a description, price and available stock. In-stock products will normally
be collected immediately by the customer from the store but may be selected for delivery to the customer's
home address for which there will be a charge. If stock is not available, the sales assistant will be able to
create a backorder for the product from a regional warehouse. The products will then either be delivered
direct from the regional warehouse to the customer's home address, or to the store for collection by the
customer. The system will allow products to be paid for by cash or credit card. Credit card transactions will
be validated via an online card transaction system. The system will produce a receipt. Order details for in-
stock products will be printed in the warehouse including the bin reference, quantity, product number and
description. These will be collected by the sales assistant and given to the customer. The sales assistant will
be able to make refunds, provided a valid receipt is produced. The sales assistant will also be able to check
stock and pricing without creating an order and progress orders that have been created for delivery.
The store manager will be able at any time to print a summary report of sales in the store for a given period,
including assignment of sales to sales assistants in order to calculate weekly sales bonuses.
The stock manager will be able to monitor stock levels and weekly run-rates in order to set minimum stock
levels and requisition products which fall below the minimum stock levels or for which demand is
anticipated. When the stock arrives, it will be booked in by the warehouse person. Stock that has been
backordered for collection from the store is held in a separate area and the store manager advised of its
arrival.
The catalogue of available products will be maintained remotely by marketing from head office. Marketing
will also be able to access sales information from each store system.
EXERCISE 3.1 [10]
Draw a complete SSD for case study given above. Also provide a description.

17 Experiment 3 – System Sequence Diagram


18 Experiment 3 – System Sequence Diagram
19 Experiment 3 – System Sequence Diagram
20 Experiment 3 – System Sequence Diagram
21 Experiment 3 – System Sequence Diagram
22 Experiment 3 – System Sequence Diagram
23 Experiment 3 – System Sequence Diagram
WEB RESOURCES
https://en.wikipedia.org/wiki/System_sequence_diagram
http://www.cs.ucc.ie/~herbert/CS4504/Larman%20chapters/larman-ch6-applying-evolutionary-
use- cases.pdf

24 Experiment 3 – System Sequence Diagram


EXPERIMENT 4 – DOMAIN MODEL

TASK 4.1: BATS SYSTEM


The Bank Accounts and Transactions System (BATS) is to be built for the Prime Bank Corporation. It must
handle clients' bank accounts and the services on these accounts, i.e., deposit, withdraw, transfer, get
balance, etc.
The transactions are recorded, because at the end of each month, the system sends out account statements to
all clients showing all transactions performed for their accounts during the last period. The system sends the
statements to the printer from where a junior clerk posts them.
The system is accessed by the bank's clients only indirectly, i.e., either via a teller, or an ATM, or the
Internet. All transactions and queries are possible via a teller; all transactions and queries are possible except
deposits via an ATM; and all except deposits and withdrawals via the Internet.
Opening an account can be performed only via a teller and the Internet; however, if a client opens an account
via the Internet, they must identify themselves with a teller to have their account activated (this is
government policy to avoid money laundering).
Closing an account can only be performed by a teller, and it requires a final statement to be sent out to the
client. The Bank offers various account types, which fall into two categories: savings and checking. Savings
accounts cannot be overdrawn. There can be a credit limit, subject to agreement by the bank, on checking
accounts; a checking account cannot be overdrawn beyond this limit.
EXERCISE 4.1 [10]
Develop a partial Domain model for the given BATS system. Identify the concepts, attributes, and
associations explicitly. This lab task submission must include:
1. List of possible conceptual classes 2. Attributes for each class
3. A partial domain model showing the conceptual classes and association between them.

1. List of possible conceptual classes


• Transaction system
• Bank account o Saving account o Checking account
• Client
• Bank system o Teller o Atm
o Internet

2. Attributes for each class


• Transaction system ▪ Id

21 Experiment 4 – Domain Model


▪ Amount
▪ type
• Bank account
▪ Name
▪ Account number
▪ balance o Saving
account
▪ Interest rate o
Checking account
▪ Credit limit
• Client
▪ Id
▪ Name
▪ Account
information
• Bank system
▪ Name
▪ Version
▪ configuration o
Teller
▪ Emp_id
▪ Emp_name
▪ Emp_contact o
Atm
▪ Id
▪ Model
▪ Cash limit o
Internet
▪ Website URL
▪ Support transaction
3. A partial domain model showing the conceptual classes and association
between them.

22 Experiment 4 – Domain Model


WEB RESOURCES
http://en.wikipedia.org/wiki/Domain_model http://csis.pace.edu/~marchese/CS389/L8/DomainModel-
UML_short.pdf http://documentation.genesez.org/javaee/de.genesez.uml.modeling.domain.html

23 Experiment 4 – Domain Model


EXPERIMENT 5 – CLASS DIAGRAM

EXERCISE 5.1 [10]


Create a class diagram for Next Generation Point of Sale Application.
The Domain Model is given below:

Reference: Applying UML and Patterns by Craig Larmen (Ch#12, Ch#16)

24 Experiment –
5 Class Diagram

WEB RESOURCES
http://en.wikipedia.org/wiki/Class_diagram
http://www.tutorialspoint.com/uml/uml_class_diagram.htm

25 Experiment –
https://www.ibm.com/developerworks/rational/library/content/RationalEdge/sep04/bell/
http://msdn.microsoft.com/en-us/library/dd409437.aspx

5 Class Diagram

EXPERIMENT 7 – ACTIVITY DIAGRAM

EXERCISE 7.1: ATM CASH WITHDRAWAL [10]


Create an activity diagram of the ATM Cash Withdrawal process explained in Experiment 7.

26 Experiment –
7 Activity Diagram

27 Experiment –
EXPERIMENT 9 – MODEL VIEW CONTROLLER (MVC)

TASK 9.1: CASE STUDY


At the beginning of each semester students are given a course catalogue containing a list of course offerings
for the semester. Information about each course, such as professor, department, and prerequisites will be
included to help students make informed decisions.
The new on-line registration system will allow students to select courses for the coming semester. The
students will have to fill an online form in which they shall provide their personal information, their
academic information and their choice of courses. The information provided shall be stored in a database
which can include:
1. Personal information
a. Name
b. Registration Number
c. Contact Number
2. Previous Academic History
a. Previous Semester’s GPA
b. Previous Semester’s courses.
3. Financial Record
a. Scholarship information (if held)
4. Degree Program registered to.
5. List of available electives from which the student can select the desired course.
6. Information for courses
a. Course/Subject Title
b. Instructor
c. Venue
d. Date and Time

28 Experiment 9 – Model View Controller (MVC)


EXERCISE
Create

9.1: MODEL Database Design. Show here: -

29 Experiment 9 – Model View Controller (MVC)


EXERCISE
Create

9.2: VIEW
Interface Design. Show here:

9.3: CONTROLLER [4]


Logic of the application (Class Diagrams). Show here: -

30 Experiment 9 – Model View Controller (MVC)


EXERCISE
Create

WEB RESOURCES
http://en.wikipedia.org/wiki/ Model–view–controller http://www.silverlightshow.net/items/Exploring-the-
Model-View-Controller-MVC-pattern.aspx http://www.slideshare.net/javierhumaran/model-view-controller-
mvc-27875933 http://poincare.matf.bg.ac.rs/~andjelkaz/pzv/cas4/mvc.pdf

31 Experiment 9 – Model View Controller (MVC)


EXPERIMENT 10 – MVC IMPLEMENTATION

EXERCISE 10.1 [10] Implement the MVC architecture designed in Experiment 9. Show
code and outcome here: - VIEW CLASS
public class LABTASK10 {

public static void main(String[] args) {


System.out.println("******************STUDENT CLASS
VIEW****************");
student st=new student();
st.setname("SaifullH");
st.setgpa(2.85);
st.setcontact(03126347225);
st.setregisteredcourse("SDA");
System.out.println("Student Name: "+st.getname());
System.out.println("Student Gpa: "+st.getgpa());
System.out.println("Student contact: "+st.getcontact());
System.out.println("Student reg no: "+st.getreg_no());
System.out.println("Student registered course: "+st.getregisteredcourse());

System.out.println("*************PROFESSOR CLASS
VIEW**************");
professor pr=new professor();
pr.setName("Sir Waqas "); pr.setId(101);
pr.setContact(03005227004);
System.out.println("Professor Name: "+pr.getName());
System.out.println("Professor id: "+pr.getId());
System.out.println("Professor contact: "+pr.getContact());

course cr=new course();


System.out.println("****************COURSE CLASS
VIEW****************");
cr.setInstructor("Sir Usman");

cr.setVenue("SE");
cr.setTitle("Principle of Management");
System.out.println("Professor name: "+cr.getInstructor());
System.out.println("Course Title: "+cr.getTitle());
System.out.println("Course Venue: "+cr.getVenue());

System.out.println("***************DEPARTMENT CLASS
VIEW**************");
department de=new department();
de.setId(19);
de.setName("Electrical Engineering ");
System.out.println("Dpertment Id: "+de.getId());
System.out.println("Department Name: "+de.getName());

32 Experiment 10 – MVC Implementation


System.out.println("*****************CONTROLLER CLASS***************");
controller co=new controller(st,pr,cr,de); co.run();
System.out.println("Hello World!");
}
}

MODEL CLASS

public class student {


Scanner sc=new Scanner(System.in);
private String name;
private int reg_no; private
long contact; private
double gpa; String
registeredcourse;
public void setname(String name)
{
this.name=name;
}
public String getname()
{
return name;
}
public void selectCourse() {
System.out.println("Courses Available: ");
System.out.println("1.SDA");
System.out.println("2.DBMS");
System.out.println("3.OOP");
System.out.println("Enter course id you want to select: ");
Scanner sc=new Scanner(System.in);
int choice=sc.nextInt();
System.out.println("'Course Selected'");
// Logic for selecting a course
}
public void fillForm() {
System.out.println("FILL FORM");
System.out.println("Form Filled");
// Logic for filling the form
}

public void registerCourse() {


System.out.println("course has been registered");
// Logic for registering a course
}

33 Experiment 10 – MVC Implementation


public class professor {
private int id; private
String name; private
long contact;

public void setId(int id) {


this.id = id;
}

public public
void setName(String
class controllername){ {
this.name = name;
private student s;
} private professor p;
public void updateCourseOutline()
private course c; {
private department d; outline has been updated");
System.out.println("Course
// Logic for updating course outline
} public controller(student s, professor p, course c, department d)
public { classthis.scourse = s; this.p = p; this.c = c; this.d = d;
{ private} String title;
private String instructor;
private String
publicvenue;
void run() {
Scanner scanner = new Scanner(System.in);
public int
void setTitle(String title)
choice;
{ this.title = title;
} do {
// Display menu options
public void setInstructor(String
System.out.println("1.instructor)
Select Course");
{ this.instructor = instructor;
System.out.println("2. Fill Form");
} System.out.println("3. Register Course");
public void viewCourseavailability()
System.out.println("4. { Update Course Outline");
System.out.println("Check course
System.out.println("5. View availability");
Course Information");
Date date =System.out.println("6.
new Date(2024, 4, 9); View Department Information");
System.out.println(date.toString());
System.out.println("0. Exit");
// Logic for System.out.print("Enter
viewing course information your choice: ");
} } choice = scanner.nextInt();
public class department {
private int id; // private
Perform actions based on user choice
String name;
switch (choice) { case 1:
s.selectCourse();
public void setId(intbreak;id) {
this.id =
case 2:id;
} s.fillForm();
break; case 3:
s.registerCourse();
public void setName(String name) {
this.name = name; break;
} case 4:
p.updateCourseOutline();
public void caltotalstudents() {
break;
System.out.println("Total case 5:
students are: "+30);
c.viewCourseavailability();
// Logic for viewing department information
break;
}

CONTROLLER

34 Experiment 10 – MVC Implementation


35 Experiment 10 – MVC Implementation
case 6:
d.caltotalstudents();
break;
case 0:

System.out.println("Exiting...");
break; default:
System.out.println("Invalid choice. Please try again.");
}
} while (choice != 0);
}
}

EXPERIMENT 11 – DESIGN PATTERNS

FACTORY PATTERN

public class FactoryPatternDemo { public class Circle implements Shape {


@Override
public static void main(String[] args) { public void draw() {
ShapeFactory shapeFactory = new System.out.println("Inside Circle::draw()
method.");
ShapeFactory(); //get an object of Circle and call its draw
method. }
Shape shape1 = shapeFactory.getShape("CIRCLE");
}//SAME CODE FOR RECTANGLE
//call draw method of Circle shape1.draw();AND SQUARE CLASS
//get an object of Rectangle and call its draw method.
Shape shape2 =
shapeFactory.getShape("RECTANGLE");
//call draw method of Rectangle shape2.draw();
//get an object of Square and call its draw method.
Shape shape3 = shapeFactory.getShape("SQUARE");
//call draw method of square
shape3.draw();
System.out.println("Hello World!");
}
}

36 Experiment 11 – Design Pattern


public interface Shape {
void draw(); }

public class Rectangle


imShapeFactoryplements Shape { {
@Overridepublic Shape getShape(String
shapeType){public void draw() {
if(shapeType == null){Syst
m.out.pri tln("Inside
Rectangle::draw() method.");return null;

}
}
if(shapeType.equalsIgnoreCase("CIRCLE"))
{
return new Circle();
} else
if(shapeType.equalsIgnoreCase("RECTAN
GLE")){
return new Rectangle();
} else
if(shapeType.equalsIgnoreCase("SQUARE"
)){
return new Square();
}
return null;
}
}

37 Experiment 11 – Design Pattern


OBSERVER PATTERN

public class Observerpatterndemo public class Subject {

public static void main(String[] args) { List<Observer> observers = new


private
Subject subject = new Subject(); ArrayList<Observer>()
new hexaobserver(subject); new ; private int state;
octalobserver(subject); new public int getState()
Binaryobserver(subject); { return state;
System.out.println("First state change:
}
15"); public void setState(int state) {
subject.setState(15); this.state = state;
System.out.println("Second statenotifyAllObservers();
change: 10"); }
subject.setState(10); public void attach(Observer observer)
} { observers.add(observer);
} }
public void notifyAllObservers(){ for
(Observer observer : observers)
{ observer.update();
}
}

38 Experiment 11 – Design Pattern


public abstract class Observer {
public class Binaryobserver extends
Observer{ protected Subject subject;
public abstract void update(); }
public Binaryobserver(Subject subject) {
this.subject = subject;
this.subject.attach(this);
}

public void update() {


System.out.println("Binary String: " +
Integer.toBinaryString(subject.getState()));
}
}//same classes for octal and hexa

39 Experiment 11 – Design Pattern


EXPERIMENT 12 – FACTORY PATTERN

EXERCISE 11.1: [2]


The classes and/or objects participating in this pattern are as given below. Create a class diagram to
represent the classes as given. You can use any other application/example that you see fit for this
design pattern.
• Product (Page)
o defines the interface of objects the factory method creates

• ConcreteProduct (SkillsPage, EducationPage, ExperiencePage) o

implements the Product interface • Creator (Document)

o declares the factory method, which returns an object of type Product. Creator may also define a
default implementation of the factory method that returns a default ConcreteProduct object.
o may call the factory method to create a Product object.
• ConcreteCreator (Report, Resume) o overrides the factory method to
return an instance of a ConcreteProduct.

40 Experiment –
12 Factory Pattern

41 Experiment –
12 Factory Pattern

EXPERIMENT 13 – OBSERVER PATTERN

EXERCISE 13.1 [10]


Consider the example where a head hunter is responsible of notifying all the registered developers of any job
opening that comes his way. All the developers in the list will be notified of the job opening. Whenever there
is some update from the head hunter, the notification is sent to all the contacts in the list. The head hunter
sends notification to all the developers without knowing who they are. Any number of developers can
subscribe to the head hunter’s list.
By using the observer pattern, what will be structure and implementation for above mentioned
example? Show design here: -

42 Experiment –
13 Observer Pattern

EXPERIMENT 14 – MODULAR DESIGN

EXERCISE 14.1 [10]


Create a Modular Design for a Hospital Management System. Show here: -

Patient module
Appointment module

1 1…*

1…*
1…*
1

1…*
Payment module

1…*
Doctor module 1…*

43 Experiment –
14 Modular Design

44 Experiment –

You might also like