You are on page 1of 2

Q1) OOP Relations

1- Create a class named Course which contains the following attributes:


code: string, name: String, number of hours: int
2- Create a class named Student which contains the following attributes:
id: String, name: String, department: String, courses: array of Courses
3- Create set and get methods for each class
in the main method:
Create three instances of Course class with the following data:
Code Name Number of hours
course1 instance CSCI 1334 Programming 1 3
course2 instance CSCI 1322 Programming 2 3
course3 instance SICT Database 1 4

Create two instances of Student class with the following data:


Id Name Department Courses
Student1 instance 1 Ali IT course1 + course 2
Student1 instance 2 Ahmed Mobile Course2 + course 3

Q2) Inheritance
1- Create a super class named LibraryItem
a. Attributes: title: String, author: String
b. Constructor with two arguments/parameters (title,author)
c. toString method to return a string with attributes values

2- Create a sub class named Book which extends LibraryItem


a. Attributes: issudeDate: String, printOutNo: String
b. Constructor with four arguments/parameters (issudeDate , printOutNo,
title,author)
c. toString method to return a string with attributes values

3- Create a sub class named CD which extends LibraryItem


a. Attributes: duration: int, playerType: int
b. Constructor with four arguments/parameters (duration, playerType,
title,author)
c. toString method to return a string with attributes values

Note: toString method in sub classes must call the toString method from the supper
class.

You might also like