You are on page 1of 8

ASSIGNMENT COVER

REGION: _MASVINGO

PROGRAM: INFORMATION TECHNOLOGY

INTAKE: _8

FULL NAME OF STUDENT: VAINAD MADZAMBA

PIN: P2069906G

MAILING ADDRESS: mdzambanvyn@gmail.com

CONTACT TELEPHONE/CELL: +263776880187

ID. NO.: 77-078453 B 77

COURSE NAME: OBJECT ORIENTED APPROACH IN SOFTWARE


DEVELOPMENT

COURSE CODE: BSEH 441

ASSIGNMENT NO. 2

DUE DATE: 27 OCTOBER 2023

ASSIGNMENT TITLE:
______________________________________________________________________________
___

______________________________________________________________________________
___

______________________________________________________________________________

MARKER’S COMMENTS: ______________________________________________________

______________________________________________________________________________
OVERALL MARK: _____________ MARKER’S NAME: ________________________

MARKER’S SIGNATURE:_______________________________ DATE: ___________

Question 1

(a) Write a code fragment that demonstrates an appropriate use of hierarchical


inheritance (i.e., a realistic scenario that would be well-suited to the use of
hierarchical inheritance).
[15]
Java
class Employee {
protected String name;
protected int employeeId;
public Employee(String name, int employeeId) {
this.name = name;
this.employeeId = employeeId;
}
public void displayInfo() {
System.out.println("Name: " + name);
System.out.println("Employee ID: " + employeeId);
}
}
class Manager extends Employee {
private String department;
public Manager(String name, int employeeId, String department) {
super(name, employeeId);
this.department = department;
}
public void displayInfo() {
super.displayInfo();
System.out.println("Department: " + department);
}
public void manageTeam() {
System.out.println("Manager is managing a team.");
}
}
class Engineer extends Employee {
private String specialization;
public Engineer(String name, int employeeId, String specialization) {
super(name, employeeId);
this.specialization = specialization;
}
public void displayInfo() {
super.displayInfo();
System.out.println("Specialization: " + specialization);
}
public void code() {
System.out.println("Engineer is coding.");
}
}
// Usage example
Employee employee = new Employee("VYN", 100);
Manager manager = new Manager("Madzamba", 200, "IT");
Engineer engineer = new Engineer("Black Tire ", 300, "Software");
employee.displayInfo();
System.out.println();
manager.displayInfo();
manager.manageTeam();
System.out.println();
engineer.displayInfo();
engineer.code();
(b) Some object oriented programming languages support method overriding. Describe
a practical situation in which method overriding might be useful.
[10]
Method overriding is a feature in object-oriented programming languages, including Java,
that allows a subclass to provide a different implementation of a method that is already
defined in its superclass. This feature is particularly useful in situations where you have a
class hierarchy and want to customize the behavior of a specific method in the subclass.
Here's a practical situation in Java where method overriding can be useful:
java
class Shape {
public void calculateArea() {
System.out.println("Area calculation not implemented for the generic shape.");
}
}
class Rectangle extends Shape {
private double width;
private double height;
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
@Override
public void calculateArea() {
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
class Circle extends Shape {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
@Override
public void calculateArea() {
double area = Math.PI * radius * radius;
System.out.println("Area of the circle: " + area);
}
}
// Usage example
Shape shape1 = new Rectangle(5, 6);
Shape shape2 = new Circle(7.5);
shape1.calculateArea();
shape2.calculateArea();
(c) A group of Open Water Swimmers have found their sport has become popular and
now wish to set up a Swimming Club. The Club will be made up of Members, who
can register online and have to provide their name, address, contact telephone
number and emergency contact name and telephone number. Each September there
is an Annual General Meeting (AGM), where Members can join a Committee to
help run the Club. The Club meets every week at a local lake, where Members can
train, or take part in lessons. The lessons are provided by Officials, who have to be
qualified. New Officials need to register online and provide evidence of what
qualifications they hold. In addition to the weekly meetings, the Club runs a series of
swims to be held on the first Saturday of each month at a different location. A
Member can nominate a potential outdoor place, which can be a river, lake or sea
and provide a classification of whether it is easy, moderate or strenuous. These will
be assessed by the Committee to decide if they are suitable and whether a quota is
needed to limit numbers. Suitable locations will be included in an online Diary
produced by the Committee. The Club charges an annual fee, which is due on the 1st
January of each year. A month after this, the Committee will generate an email to
remind any Members who have forgotten to pay.
i. Draw a Use Case diagram for the Swimming Club.
[15]
ii. Discuss how Use Case diagrams and scenarios contribute to the development
of a system. Within your answer include an example scenario from the
Swimming Club.
User case diagrams and scenarios are both valuable tools in the development of a
system as they help capture and analyze the functional requirements and
interactions between users and the system. Let's explore how each of these
contributes to system development:

1. Use Case Diagrams:


Use case diagrams provide a visual representation of the system's functionality
from a user's perspective. They depict the interactions between actors (users or
external systems) and the system, showcasing the various use cases or activities
that can be performed. Use case diagrams contribute to system development in the
following ways:

- Requirement Analysis: Use case diagrams help identify and clarify the
functional requirements of the system. They capture the range of actions and
interactions that users can perform, providing a comprehensive overview of the
system's intended behavior.
- Scope Definition: Use case diagrams assist in defining the boundaries and scope
of the system. They help identify the actors involved, the system's responsibilities,
and the external systems or components it interacts with.
- Communication and Collaboration: Use case diagrams serve as a communication
tool between stakeholders, developers, and designers. They provide a common
understanding of the system's expected behavior and facilitate discussions around
requirements and functionalities.

Example Scenario from a Swimming Club:


In the context of a swimming club, a use case diagram might include actors such
as Club Member, Coach, and Administrator. Some use cases could be "Register
for a Swim Meet," "Schedule Practice Sessions," and "Generate Monthly
Reports." These use cases capture the key interactions between the actors and the
system, representing the core functionalities of the swimming club management
system.

2. Scenarios:
Scenarios, often written as use case scenarios or user stories, provide detailed
narratives or descriptions of specific interactions or sequences of actions between
users and the system. Scenarios contribute to system development in the following
ways:

- Detailed Understanding: Scenarios offer a deeper understanding of how users


will interact with the system and the expected outcomes. They describe the
specific steps, inputs, and expected outputs, providing a more detailed perspective
on system behavior.
- Validation and Verification: Scenarios can be used to validate and verify the
system's functionality. They enable testing and simulation of user interactions,
allowing developers to ensure that the system meets the desired requirements and
behaves as expected.
- Design and Implementation Guidance: Scenarios guide the design and
implementation of the system by providing concrete examples of user interactions.
They help developers identify the necessary features, user interfaces, and system
responses required to fulfill the user's needs.

Example Scenario from a Swimming Club:


In the swimming club scenario, an example use case scenario could be "Coach
Schedules Practice Session." It would outline the steps involved, such as the coach
logging into the system, selecting the desired date and time, specifying the pool
location, and saving the session. The scenario would also describe the expected
outcome, such as the session being added to the club's practice schedule and
notifying the members. This scenario provides clear guidance on how the system
should handle coach-initiated practice session scheduling.

In summary, use case diagrams and scenarios complement each other in system
development. Use case diagrams provide a high-level view of the system's

You might also like