Try It Yourself: ifs and Boolean Expressions

  1. Suppose we have a Circle class with the following methods:
    public Circle(Point centerPt, double r) constructs a circle with the given center point and radius
    public Point getCenter() returns the Point center point of the circle
    public double getRadius() returns the double radius value of the circle
    public void setRadius(double newR) sets the radius to the value given
    public void setCenter(Point newCenter) sets the center point to the point given
    public double computeArea() returns the double area of the circle
    public double computeCircumference() returns the double circumference of the circle
    1. Write the contains method for the Circle class. The method should take a Point as an argument and return true if the given point is inside the circle and false otherwise.
    2. Write a method isInside that takes two Circle objects as arguments and returns true if the second circle is completely inside the first circle and returns false otherwise. That is, the isInside method should have the following signature:
      boolean isInside(Circle outer, Circle inner)


  2. Write a Date class. It must contain (at least) the following public methods:
    Date(int m, int d, int y) Creates a Date object with the given month (1 <= m <= 12), day (1 <= d <= 31), and year (1000 <= y <= 9999).  The arguments passed in are checked for validity; invalid arguments are replaced with 0.
    int getMonth() Returns the month.
    int getDay() Returns the day.
    int getYear() Returns the year.
    String toString() Returns a string representation of the Date object (suitable for printing). The date is represented in the format mm/dd/yyyy (e.g. 3/29/2000).