Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Okay, we need a rectangle class. This is not the same as the rectangle class in

ID: 3556762 • Letter: O

Question

Okay, we need a rectangle class. This is not the same as the rectangle class in the book. Your killer programming skills have earned you a job languishing in the property assessor's office. The office keeps track of land for the county. Property is only measured in rectangles. You need a rectangle class with the following methods: constructor - takes a point, a height and a width. the point is the lower left corner of the rectangle. area - returns the area of the rectangle addarea - adds the area of two rectangles - you need to check for the rectangles overlapping and return an error code if they overlap. perimeter - returns the perimeter of a rectangle.

Explanation / Answer

Dear,

import java.util.Scanner;

class Point
{
    public int x = 0;
    public int y = 0;
    //A constructor!
    public Point(int x, int y)
    {
        this.x = x;
        this.y = y;
    }
}
class Rectangle
{
        /** The width of this rectangle. */
        public int width;

        /** The height of this rectangle. */
        public int height;

        /** The origin (lower-left corner) of this rectangle. */
        public Point origin;

        /**
         * Creates a rectangle with the specified size.
         * The origin is (0, 0).
         * @param w width of the rectangle
         * @param h height of the rectangle
         */
        public Rectangle(int w, int h) {
       this(new Point(0, 0), w, h);
        }

        /**
         * Creates a rectangle with the specified origin and
         * size.
         * @param p origin of the rectangle
         * @param w width of the rectangle
         * @param h height of the rectangle
         */
        public Rectangle(Point p, int w, int h) {
       origin = p;
       width = w;
       height = h;
        }

     
        /**
         * Returns area of the rectangle.
         */
        public int area()
        {
          return width * height;
        }
        /**
         * Returns perimeter of the rectangle.
         */
        public int Perimeter()
        {
           return 2*(width+ height);
        }
        /**
         * display whether two rectangles Overlaps
         */
        public void Overlaps(Rectangle r1)
        {
           if(origin.x==r1.origin.x||origin.y==r1.origin.y)
               System.out.print("Rectangle overlaps!!");
           else
               System.out.print("No overlaps!!");
              
        }
   }

Hope this will help you!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote