Try It Yourself: Defining Instantiable Classes

  1. Write the code for the instantiable class PlayingCard that represents a playing card. The following information is provided (i.e., this is the public interface). Comment any assumptions that you make.
    PlayingCard(String suitName, int faceValue) constructs a playing card with the given suit and value
    getSuit() returns the String suit of the card
    getFaceValue() returns the int face value of the card


  2. Write the code for the instantiable class Circle that represents a circle in the xy plane. The following information is provided. For points, assume you have this simple Point class. Comment any assumptions that you make.
    Circle(Point centerPt, double r) constructs a circle with the given center point and radius
    getCenter() returns the Point center point of the circle
    getRadius() returns the double radius value of the circle
    setRadius(double newR) sets the radius to the value given
    setCenter(Point newCenter) sets the center point to the point given
    computeArea() returns the double area of the circle
    computeCircumference() returns the double circumference of the circle


  3. Write the code for the instantiable class Rectangle that represents a rectangle in the xy plane. The following information is provided. For points, assume you have this simple Point class. Comment any assumptions that you make.
    Rectangle(Point upperLeftPt, double h, double w) constructs a rectangle with the given height h and width w whose upperleft corner is at the given point
    getUpperLeft() returns the Point upperleft corner point of the rectangle
    getHeight() returns the double height of the rectangle
    getWidth() returns the double width of the rectangle
    computeArea() returns the double area of the rectangle
    computePerimeter() returns the double perimeter of the rectangle
    scale(double factor) scales the dimensions of the rectangle by the given factor
    shift(Point p) shifts the upperleft corner of the rectangle to the point given