Programing 2 - Lab 03
Programing 2 - Lab 03
Page 1 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 03
-------------------------------------------------------------------------------------------------------------------------------
• A method named addCourse() to add courses registered by this student.
• A method named showData() to display the student information.
The class Course contains:
• Private data fields named crsName, code, and a collection of Student-
objects.
• The constructor to initialize the data fields.
• The setter and getter methods.
• A method named numOfStudents to determine the number of students that
will register this course.
• A method named addStudent to add student registered this course.
• A method named showData to display the course information.
Question 2. Design two classes named Author and Book. [Draw the class
Diagram]
The class Book contains:
• The data fields name and price.
• The constructor to initialize the data fields.
• The setter and getter methods.
Page 2 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 03
-------------------------------------------------------------------------------------------------------------------------------
• A method named show that displays the book’s information.
The class Author contains:
• The data fields name, email, gender, and collection of Book-objects.
• The constructor to initialize the data fields.
• The setter and getter methods.
• A method named showdata that displays the author’s information and his/her
book information.
• A method named books_number that returns the number of books this author
has.
Write a main program to test your classes.
Part 3: HOMEWORK.
Question 1. Design a class named Circle to represent a Circle.
The class contains:
a. The data fields radius.
b. A no-arg constructor that circle with radius=1.
c. A constructor that constructs a circle with specified radius.
d. A method names getArea(), which return the area of the circle.
e. A method named getCir() that returns the circumference of the circle.
f. A method named compare(Circle c) that returns 0 if the class circle and circle
c has the same radius, return 1 if class radius is greater than circle c, and
return -1 if the class radius less than circle c.
g. A method named toString() that returns String contains all Circle information.
Then write a Java code for the described class. Finally, write a test program that
contains the main method and extra methods to perform the following operations:
A method to read array of objects from Circle.
A method to get the sum of areas of all circles in the array.
A method to get the sum of circumferences of all circles in the array.
A method to display all the Circles information.
A method to Compare all radius for all array objects and return a Boolean matrix
for the comparison, then display this matrix in main.
Page 3 of 4
Alexandria National University
Faculty of Computer and Information
Lecturer: Dr. Amr AboHani, Dr. Ahmed Saleh, Dr. Ahmed Moustafa
Course: Programming 2
Lab #: 03
-------------------------------------------------------------------------------------------------------------------------------
Question 2. Design two classes named Person and Car. [Draw the class Diagram]
The class Car contains:
• The data fields model and licenseNum.
• The constructor to initialize the data fields.
• The setter and getter methods.
• A method named show that displays the car’s information.
The class Person contains:
• The data fields name, idNum, and object of type Car.
• The constructor to initialize the data fields.
• The setter and getter methods.
• An Own method to own a car.
• A Disown method to disown his/her car.
• A method named showdata that displays the person’s information and his/her
car information.
Write a main program to test your classes.
Page 4 of 4