Table of Contents

Lesson 4

Classes and objects relations.

Objectives

Documentation

Pachete java
Specificatori de acces
Reutilizarea claselor
Thinking in Java : Chapter 6 - Reusing classes

Exercises

Exercise 1

Import conveyor-belt application from here in your editor. Add junit library in the project path and resolve the tasks described in the readme file.

Exercise 2 (Optional)

Considering exercise 6 from lab3, create unit tests for MyPoint class.

Exercise 3

Follow the instructions bellow and implement the program. Create a test class for testing the program.

A class called circle is designed as shown in the following class diagram. It contains:

Exercise 4

Follow the instructions bellow and implement the program. Create a test class for testing the program.

A class called Author is designed as shown in the class diagram. It contains:

Exercise 5

Follow the instructions bellow and implement the program. Create a test class for testing the program.

A class called Book is designed as shown in the class diagram. It contains:

Exercise 6

Follow the instructions bellow and implement the program. Create a test class for testing the program.

Modify the Book class from previous exercise to support one or more authors by changing the instance variable authors to an Author array. Reuse the Author class written earlier.

Notes:

Exercise 7

Follow the instructions bellow and implement the program. Create a test class for testing the program.

In this exercise, a subclass called Cylinder is derived from the superclass Circle as shown in the class diagram.

Notes:

Exercise 8

Follow the instructions bellow and implement the program. Create a test class for testing the program.

Write a superclass called Shape (as shown in the class diagram), which contains:

The Circle class contains:

The Rectangle class contains:

Write a class called Square, as a subclass of Rectangle. Square has no instance variable, but inherits the instance variables width and length from its superclass Rectangle.

Exercise 9 (Optional)

Implement the program described in Chapter 2 - Learn with robots - Problem Set - 2.12 (page 110)