[go: up one dir, main page]

0% found this document useful (0 votes)
44 views3 pages

POO Hands On5

This document outlines 11 exercises for an Object-Oriented Programming course. The exercises involve writing Java programs that create classes to model real-world entities like people, courses, books, and employees. They demonstrate OOP concepts like class definitions, objects, methods, inheritance, composition, and aggregation. Later exercises build more advanced employee and library management systems to practice class design and interacting objects.

Uploaded by

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

POO Hands On5

This document outlines 11 exercises for an Object-Oriented Programming course. The exercises involve writing Java programs that create classes to model real-world entities like people, courses, books, and employees. They demonstrate OOP concepts like class definitions, objects, methods, inheritance, composition, and aggregation. Later exercises build more advanced employee and library management systems to practice class design and interacting objects.

Uploaded by

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

Abdelhamid Mehri University – Constantine 2

NTIC Faculty
Second year common core
2023–2024

Object-Oriented Programming 1 (POO1)


Hands-On – Series 01

Exercise 1: A First Java Program in Eclipse


Write a Java program in Eclipse that displays on the screen: your first name, last name, group, and age.
To do so, use Eclipse to create a project ’HandsOn’, and within this project a package ’Tp1’, and finally
the class ’Exercise1’.

Exercise 2: Classes in Java


Without giving their details (attributes and methods), define the following classes in Java: ’Person’,
’Student’, ’Teacher’, ’Course’.

Exercise 3: Attributes
Enrich the ’Course’ and ’Person’ classes defined in Exercise 2 above with:
- A set of attributes: last_name, f irst_name, and age for the ’Person’ class, and course_code and
teacher_code for the ’Course’ class.
- A set of empty methods representing the behavior of objects of these classes.

Exercise 4: Objects and Messages


Define a main program to:

1. Create two objects p and f of type ’Person’.


2. Display the values of their attributes.
3. Modify the attribute values of object p with values of your choice and display the values of its
attributes.
4. Create an object t of type ’Teacher’.
5. Define a method createCourse in the ’Teacher’ class to create an object of type ’Course’.
6. Perform the creation of an object c of type ’Course’ by calling the createCourse method of object t
(of type ’Teacher’).
7. Display the value of the course_code attribute of object c.
8. Modify this value and display the new value.
Exercise 5: More Classes and Objects

1. Define additional classes in Java such as ’Book’, ’Library’, and ’Author’. Mention the attributes and
methods you would include for each class.
2. Instantiate objects of the ’Book’, ’Library’, and ’Author’ classes.
3. In a Main class, perform operations on these objects to showcase their functionality.

Exercise 6: Advanced Attributes and Methods


1. Extend the ’Person’ class by adding detailed attributes such as address, contact information, etc.
2. Implement methods to update and display the added information for a ’Person’ object.
3. Extend the ’Course’ class with additional attributes like duration, location, etc.
4. Implement methods to manipulate and display this additional information for a ’Course’ object. Use
them in a Main class.

Exercise 7: Composition and Aggregation


1. Create a class ’University’ in Java.
2. Implement methods to add and remove ’Department’ objects within the ’University’.
3. Define a ’Department’ class with appropriate attributes and methods.
4. Instantiate a ’University’ object and add multiple ’Department’ objects to it.
5. Display the list of departments within the university.

Exercise 8: Library Management System


1. Create a class ’Book’ in Java with attributes like title, author, and ISBN.
2. Define a class ’Library’ that can store multiple ’Book’ objects.
3. Implement methods in the ’Library’ class to add, remove, and display books.
4. Instantiate a ’Library’ object and add several ’Book’ objects to it.
5. Create a ’Main’ class to demonstrate the functionality of your library management system. Add,
remove, and display books using the library object.

Exercise 9: Employee Management System


1. Create a class ’Employee’ in Java with attributes like name, employee ID, and salary.
2. Define a class ’Company’ that can manage a list of ’Employee’ objects.
3. Implement methods in the ’Company’ class to hire, fire, and display employees.
4. Instantiate a ’Company’ object and hire several ’Employee’ objects.
5. Create a ’Main’ class to showcase the employee management system. Hire, fire, and display employee
information using the company object.

2
Exercise 10: Advanced Employee Management System
1. Create a class ’Address’ in Java with attributes like street, city, and postal code.
2. Modify the ’Employee’ class to have an attribute address of type ’Address’.
3. Define a class ’Company’ that can manage a list of ’Employee’ objects.
4. Implement methods in the ’Company’ class to hire, fire, and display employees along with their
addresses.
5. Create a ’Main’ class to showcase the employee management system. Hire, fire, and display employee
information along with their addresses using the company object.

Exercise 11: Understanding Primitive Types in Java


1. List and describe the eight primitive data types in Java.
2. Create a Java class that demonstrates the use of each primitive data type. Initialize variables with
appropriate values and display them.
3. Illustrate the usage of boolean and character data types in Java with appropriate examples.
4. Describe the purpose and usage of the ’String’ class in Java. Provide examples of string manipulation.

You might also like