Try It Yourself: ifs and Boolean Expressions Solution

  1.  
    1. Answer: The following code would be inside the Circle class:
      public boolean contains(Point p) {
      	// A point p is inside a circle if the distance between p and the
      	// circle's center is less than the radius of the circle.
      	return (center.distance(p) < radius);
      }
      
    2. Answer: The following code would be outside the Circle class:
      boolean isInside(Circle outer, Circle inner) {
      
      	Point outerCenter = outer.getCenter();	// the outer circle's center
      	Point innerCenter = inner.getCenter();	// the inner circle's center
      
      	// The inner circle is completely inside the outer circle if:
      	// 	distance between centers 
      	//		+ 				< 	outer circle's radius
      	//	inner circle's radius 		
      	return (outerCenter.distance(innerCenter) + inner.getRadius() 
      	        < outer.getRadius());
      }
      


  2.  
    public class Date {
    	private int month, day, year;  // holds month, day, year for date
    
    	/**
    	 * Creates a Date object with the given month, day, and year.  
    	 * Invalid arguments are replaced with 0.
    	 *
    	 * @param m the month (1 <= m <= 12)
    	 * @param d the day (1 <= d <= 31)
    	 * @param y the year (1000 <= y <= 9999)
    	 **/
    	public Date(int m, int d, int y) {
    		month = m;
    		if (month < 1 || month > 12)
    			month = 0;
    		day = d;
    		if (day < 1 || day > 31)
    			day = 0;
    		year = y;
    		if (year < 1000 || year > 9999)
    			year = 0;
    	}
    
    	/**
    	 * Returns the month.
    	 * @return the month
    	 **/
    	public int getMonth() {
    		return month;
    	}
    
    	/**
    	 * Returns the day.
    	 * @return the day
    	 **/
    	public int getDay() {
    		return day;
    	}
    
    	/**
    	 * Returns the year.
    	 * @return the year
    	 **/
    	public int getYear() {
    		return year;
    	}
    
    	/**
    	 * Returns a String representing the date.
    	 * @return the date in the format: mm/dd/yyyy
    	public String toString() {
    		return (month + "/" + day + "/" + year);
    	}
    }