0% found this document useful (0 votes)
2 views17 pages

Mock TCA CSY2094 Systems Design

The document outlines a mock assessment for a Systems Design & Development course, including questions on class diagrams, Java inheritance, and ArrayList implementation. It covers various object-oriented programming concepts such as association, aggregation, composition, and inheritance, along with practical coding tasks. Additionally, it includes a quiz section to match Java keywords with their functions and questions on OOP principles.

Uploaded by

trackjjim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views17 pages

Mock TCA CSY2094 Systems Design

The document outlines a mock assessment for a Systems Design & Development course, including questions on class diagrams, Java inheritance, and ArrayList implementation. It covers various object-oriented programming concepts such as association, aggregation, composition, and inheritance, along with practical coding tasks. Additionally, it includes a quiz section to match Java keywords with their functions and questions on OOP principles.

Uploaded by

trackjjim
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Mock TCA CSY2094 Systems Design & Development

DURATION: 2 hours TOTAL MARKS AVAILABLE: 50

1. Class Diagrams describe the data found in a software system

(i) Relationships in Class Diagrams indicate that there are links required by

objects in order to accomplish a task. Describe the following 4 different types

of relationships that can be found in a Class Diagram:

(a) Association

(b) Aggregation

(c) Composition

(d) Inheritance

(1,1,2,2)

(ii) Create a class diagram to satisfy the following specification for an online
hotel

booking system:

The system has multiple users, each with a name and contact number. There

are two types of users:

1. Guests, who have a payment method and can book up to 3 rooms.

2. Hotel Managers, who have a username and password to manage bookings

and room availability.

Each hotel room has a room number, room type, and price per night. Guests

can browse available rooms and make reservations online.

(15)

2. Write Java code to do the following using inheritance:

a. Create a superclass called Vehicle with the following method:

b. Create a subclass called Car that extends Vehicle with the following
properties:

• An attribute horsepower.
• A constructor that takes a parameter to set the horsepower attribute.

• A maxSpeed() method that calculates and returns the maximum speed of


the

car (assume maxSpeed = horsepower * 2).

c. Create a main method to create a Car object and call its maxSpeed()
method.

• State what the maximum speed would be for your object.

(3, 10, 5)

3. Create Write a Java program that uses an ArrayList to store Employee


objects, each

having attributes like id, name, salary, and department. The program should
perform

the following operations: first, add five Employee objects to the list. Calculate
and

print the total salary of all employees.

(11)

Mock TCA CSY2094 Systems Design & Development

Question 1: Class Diagrams

(i) Different types of relationships in Class Diagrams:

(a) Association

Association represents a general relationship between two classes indicating


that objects of one class are connected to objects of another class. It's
represented by a simple line between classes and shows that objects know
about each other and can interact. For example, a Teacher teaches a
Student.

(b) Aggregation

Aggregation is a specialized form of association representing a "whole-part"


or "has-a" relationship. It's represented by a hollow diamond at the "whole"
end. The key characteristic is that the "part" objects can exist independently
of the "whole" - they have their own lifecycle. For example, a Department
has Employees, but Employees can exist even if the Department is dissolved.
(c) Composition

Composition is a stronger form of aggregation representing a "contains-a"


relationship. The "part" objects cannot exist independently of the "whole" - if
the "whole" is destroyed, the "parts" are also destroyed. It's represented by a
filled diamond at the "whole" end. For example, a House contains Rooms,
and if the House is demolished, the Rooms no longer exist.

(d) Inheritance

Inheritance represents an "is-a" relationship between classes, where one


class (the subclass) inherits attributes and methods from another class (the
superclass). The subclass can add new attributes/methods or override
existing ones. It's represented by an arrow pointing from the subclass to the
superclass, with a hollow triangular arrowhead. Inheritance enables code
reuse and polymorphism. For example, a Car is a Vehicle.

(ii) Class diagram for an online hotel booking system:

+----------------+ +----------------+

| User | | Room |

+----------------+ +----------------+

| - name: String | | - roomNumber: int |

| - contactNumber: String | | - roomType: String |

+----------------+ | - pricePerNight: double |

/\ +----------------+

| /\

| |

+------+-------+ +-----+------+

| | | |

| +---------+ | +-------+--------+ |

| | Guest | | | HotelManager | |

| +---------+ | +----------------+ |

| | - paymentMethod: String | | - username: String |

| +---------+ | | - password: String |


| | +----------------+ |

+--------------+ | |

| | |

| | |

v v |

+----------------+ | |

| Reservation |<-------+ |

+----------------+ |

| - checkInDate: Date | |

| - checkOutDate: Date | |

+----------------+ |

Notes:

 User is a superclass with name and contactNumber attributes

 Guest extends User and has a paymentMethod attribute

 HotelManager extends User and has username and password


attributes

 Room has roomNumber, roomType, and pricePerNight attributes

 Guest can book up to 3 rooms (shown by the association with


Reservation)

 HotelManager manages bookings and room availability

Question 2: Java code using inheritance

a. Create a Vehicle superclass:

public class Vehicle {

public void drive() {

System.out.println("The vehicle is driving");

}
b. Create a Car subclass:

public class Car extends Vehicle {

private int horsepower;

public Car(int horsepower) {

this.horsepower = horsepower;

public int maxSpeed() {

return horsepower * 2;

c. Create a main method:

public class Main {

public static void main(String[] args) {

Car myCar = new Car(100);

int maxSpeed = myCar.maxSpeed();

System.out.println("The maximum speed of the car is: " + maxSpeed +


" mph");

The maximum speed would be 200 mph for a Car object with 100
horsepower.

Question 3: Java program with ArrayList

import java.util.ArrayList;

class Employee {

private int id;


private String name;

private double salary;

private String department;

public Employee(int id, String name, double salary, String department) {

this.id = id;

this.name = name;

this.salary = salary;

this.department = department;

public double getSalary() {

return salary;

public class EmployeeManagement {

public static void main(String[] args) {

ArrayList<Employee> employees = new ArrayList<>();

// Add five Employee objects

employees.add(new Employee(1, "John Smith", 45000, "IT"));

employees.add(new Employee(2, "Mary Jones", 55000, "HR"));

employees.add(new Employee(3, "David Wilson", 60000, "Finance"));

employees.add(new Employee(4, "Sarah Brown", 48000, "Marketing"));

employees.add(new Employee(5, "Michael Davis", 65000, "Operations")


);
// Calculate total salary

double totalSalary = 0;

for (Employee emp : employees) {

totalSalary += emp.getSalary();

// Print total salary

System.out.println("Total salary of all employees: $" + totalSalary);

Question 1: Match the Java keywords related to OOP with their


functions.

Match each term with its correct function:

1. super

o Calls a superclass constructor ✓

o Refers to the current object instance

o Establishes an inheritance relationship between classes

o Invokes a static method

2. this

o Calls a superclass constructor

o Refers to the current object instance ✓

o Locks access to an instance method

o Prevents inheritance

3. extends

o Calls a superclass constructor

o Refers to the current object instance

o Establishes an inheritance relationship between classes ✓


o Implements an interface

4. final

o Invokes a static method

o Creates a new instance

o Makes a variable volatile

o Prevents inheritance, method overriding, or variable


reassignment ✓

Question 2: You need to implement a method that calculates the


factorial of a given positive integer. Which loop structure would be
most appropriate for this task?

 for loop ✓

 do-while loop

 switch statement

 while loop

Question 3: What will be the output of this code?

public class MyClass {

int x;

public MyClass() {

x = 5;

public class Test {

public static void main(String[] args) {

MyClass obj = new MyClass();

System.out.println(obj.x);

 Compilation error
 5✓

 0

 Runtime error

Question 4: What does the getModel() method return?

public class Car {

private String make;

private String model;

public Car(String make, String model) {

this.make = make;

this.model = model;

public String getModel() {

return model;

 The make of the car

 Both the make and model of the car

 The model of the car ✓

 Nothing, it's a constructor

Question 5: In Java, the process of creating a new class by reusing


the properties and behaviors of an existing class is known as
_________

 inheritance ✓

 polymorphism

 encapsulation
 abstraction

Question 6: In Java, what is the primary purpose of the super


keyword?

 To declare a variable

 To create a new instance of a class

 To call the superclass constructor ✓

 To access a static method

Question 7: In Java, all objects are passed by reference to methods,


allowing the modification of the original object.

 True

 False ✓

Question 8: You need to ensure that a specific block of code is


executed only if a certain condition is met. Which Java construct
should you use?

 switch case

 for loop

 if statement ✓

 while loop

Question 9: Java supports multiple inheritance, allowing a class to


inherit from multiple classes.

 True

 False ✓

Question 10: A class's private members are typically accessed


through public methods known as _________

 getters and setters ✓

 accessors and mutators

 interfaces

Focused TCA Questions for 1-2 Hour Assessment


Class Diagrams (30-40 minutes)

Question 1: UML Relationships

Briefly describe the following relationships in UML class diagrams


and provide a real-world example for each:

 Association

 Aggregation

 Composition

 Inheritance

Expected answers:

 Association: Simple relationship between classes (Teacher teaches


Student)

 Aggregation: "Has-a" relationship where parts can exist


independently (Department has Employees)

 Composition: "Contains-a" relationship where parts cannot exist


without the whole (House contains Rooms)

 Inheritance: "Is-a" relationship where subclass inherits from


superclass (Car is a Vehicle)

Question 2: Create a Class Diagram

Create a class diagram for a university enrollment system with:

 Student class with id, name, email

 Course class with code, title, credits

 Students can enroll in multiple courses

 Each course can have multiple students

 Include appropriate attributes and methods

Java Implementation (30-40 minutes)

Question 3: Inheritance Implementation

Create a Shape hierarchy with:

 Abstract Shape class with color attribute and abstract area() method
 Circle and Rectangle classes that extend Shape

 Main method that creates and displays information about both shapes

Sample solution structure:

public abstract class Shape {

protected String color;

public abstract double area();

public class Circle extends Shape {

private double radius;

// Constructor, area implementation, toString

public class Rectangle extends Shape {

private double length;

private double width;

// Constructor, area implementation, toString

public class Main {

public static void main(String[] args) {

// Create instances, call methods

Question 4: ArrayList Implementation

Create a program that:

 Uses an ArrayList to store Book objects with title, author, and price

 Implements methods to add books and calculate the total price

 Main method that adds at least 3 books and displays the total

OOP Concepts (20-30 minutes)


Question 5: Short Answer Questions

Answer the following OOP concept questions:

a) What is the difference between an abstract class and an interface?

b) Explain the concept of polymorphism with an example.

c) What are the benefits of encapsulation in OOP?

d) Which access modifier would you use for:

 A class constant that should be accessible anywhere

 A method that only child classes should access

 A field that should only be accessible within its own class

Question 6: Code Analysis

What will be the output of the following code? Explain your answer.

public class Parent {

public void display() {

System.out.println("Parent display");

public class Child extends Parent {

@Override

public void display() {

System.out.println("Child display");

public void show() {

super.display();

this.display();

}
public class Main {

public static void main(String[] args) {

Child c = new Child();

c.show();

Quiz with Complete Answer Options

Question 1: Match the Java keywords related to OOP with their


functions.

Match each term with its correct function:

1. super

o Calls a superclass constructor ✓

o Refers to the current object instance

o Establishes an inheritance relationship between classes

o Invokes a static method

2. this

o Calls a superclass constructor

o Refers to the current object instance ✓

o Locks access to an instance method

o Prevents inheritance

3. extends

o Calls a superclass constructor

o Refers to the current object instance

o Establishes an inheritance relationship between classes ✓

o Implements an interface

4. final

o Invokes a static method


o Creates a new instance

o Makes a variable volatile

o Prevents inheritance, method overriding, or variable


reassignment ✓

Question 2: You need to implement a method that calculates the


factorial of a given positive integer. Which loop structure would be
most appropriate for this task?

 for loop ✓

 do-while loop

 switch statement

 while loop

Question 3: What will be the output of this code?

public class MyClass {

int x;

public MyClass() {

x = 5;

public class Test {

public static void main(String[] args) {

MyClass obj = new MyClass();

System.out.println(obj.x);

 Compilation error

 5✓

 0

 Runtime error
Question 4: What does the getModel() method return?

public class Car {

private String make;

private String model;

public Car(String make, String model) {

this.make = make;

this.model = model;

public String getModel() {

return model;

 The make of the car

 Both the make and model of the car

 The model of the car ✓

 Nothing, it's a constructor

Question 5: In Java, the process of creating a new class by reusing


the properties and behaviors of an existing class is known as
_________

 inheritance ✓

 polymorphism

 encapsulation

 abstraction

Question 6: In Java, what is the primary purpose of the super


keyword?

 To declare a variable
 To create a new instance of a class

 To call the superclass constructor ✓

 To access a static method

Question 7: In Java, all objects are passed by reference to methods,


allowing the modification of the original object.

 True

 False ✓

Question 8: You need to ensure that a specific block of code is


executed only if a certain condition is met. Which Java construct
should you use?

 switch case

 for loop

 if statement ✓

 while loop

Question 9: Java supports multiple inheritance, allowing a class to


inherit from multiple classes.

 True

 False ✓

Question 10: A class's private members are typically accessed


through public methods known as _________

 getters and setters ✓

 accessors and mutators

 interfaces

 constructors

You might also like