Exercise 1:

Write a class called Rational for perfoming arithmetic with fractions.

Requisites:


Exercise 2:

The target of this exercise is to create classes to represent 2-D trajectories, and provide methods to draw them.

We define a trajectory as a path or line in a two dimensional space or plane, between two points. Note that a trajectory is an infinite series of continous positions (x,y).

Spiral

In this exercise, we will model the trajectories as 100 points joined with straight lines. These 100 points will be distributed from the begining until the end of the real trajectory. To calculate the positions (x,y) of these 100 points, we will use two functions/methods, called X and Y. These methods are parameterized with a integer value N, ranging from 0 to 99, and they will return the coordenates of the N-th point of the trajectory.

Spiral
We have written a class, called Display, that implement a window where we can draw. It has methods to draw lines, circles, manage colors, and so on. This class can be obtained from Display.java. We will use this class to create the windows where we are going to draw.

CircularT.java is a class, also provided by us, that implements circular trajectories. The constructor of this class takes as parameter the radius of the circular trajectory. The methods X and Y calculate the position (x,y) of the n-th trajectory sample. The method Draw draws the trajectory in a given display and centered in a given position.

TestT.java is a program that tests this class.

Compile these files and execute TestT.

Now, write the following new trajectory classes:

Modify the TestT program to test the new classes.

These new classes must be written duplicating the file CircularT.java, and modifying just the necessary Java code source lines. That is: