Java

OOP GUIDE / WORK

 

CIRCLE CLASS 2

 

Topics

  • Instance variables
  • Constructors
  • Constructor overloading
  • Using objects as parameters

 

 

TASK – PART 1 – SETTING UP THE POINT CLASS

 

Copy and paste the following Point class into your IDE to use it in this problem.

 

public class Point

{

   public double x;

   public double y;

 

   public Point(double tx, double ty)

   {

       xtx;

       yty;

   }

 

   public Point()

   {

       x = 0.0;

       y = 0.0;

   }

}

 

 

TASK – PART 2 – CIRCLE CLASS


Create a Circle class. 

 

The only data we need to store is the circle's radius. 

 

Constructor #1: A constructor that gets a value for radius and creates the circle.

Constructor #2: A constructor that gets no parameters and creates a unit circle – essentially a circle with a radius of 1.

 

Constructor #3: A constructor that gets two Point objects.  It then calculates the distance between the two points and creates a circle with that information.

 

 

TASK – PART 3 – TESTING THE CIRCLE CLASS


Create the class.  Test it inside the main function of another class.