Question
In Java Class Writing to Rectangle: Rectangles Complete operations using classes as constructors, getter setters and some operations. Properties will specify x and y coordinates.
In Java Class Writing to Rectangle:
Rectangles Complete operations using classes as constructors, getter setters and some operations. Properties will specify x and y coordinates. (Controls at the bottom left) In the following, the direction will be rotated from the corner of the square.
The Class Definition Like this :
public class Rectangle {
private int x; // left-bottom corner rectangle private int y; // left-bottom corner rectangle private int width; private int height; public Rectangle(int x, int y, int width, int height) { } public Rectangle(int width, int height) { // constructs a rectangle which has left-bottom corner on the origin (0,0) with given width and height } public int getX() { // returns left-bottom corner's x coordinate } public int getY() { // returns left-bottom corner's y coordinate } public int getWidth() { // returns width } public int getHeight() { // returns height } public void reshape(int x, int y, int width, int height) { // changes the width, height and coordinates of the rectangle according to passed values } public void resize(int width, int height) { // changes the width and height of the rectangle according to passed values } public void setLocation(int px, int py) { // changes the coordinates of the rectangle according to passed values }
public void printLocation() { // prints the coordinates of the left-bottom corner's coordinates (x,y) } r public void printCoordinates() { // prints the coordinates of every corne } public void translate(int dx, int dy) { // translates the rectangle and changes the coordinates according to passed values } public void rotateClockwise() { // rotates the rectangle 90 degrees clockwise around its left-bottom corner } public void rotateCounterClockwise() { // rotates the rectangle 90 degrees counter-clockwise around its left-bottom corner } public boolean contains(int x, int y) { // returns true if a given point is inside or on the rectangular area else returns false }
public static void main(String args[]) { // function calls } }
Sample Output:
Rectangle 1: Left-Bottom: (0,0) Left-Top: (0,6) Right-Top: (5,6) Right-Bottom: (5,0)
Rectangle 1 rotated clockwise: Left-Bottom: (0,-5) Left-Top: (0,0) Right-Top: (6,0) Right-Bottom: (6,-5) Rectangle 1 rotated counter-clockwise: Left-Bottom: (-5,-5) Left-Top: (-5,1) Right-Top: (0,1) Right-Bottom: (0,-5) Rectangle 2: Left-Bottom: (3,5) Left-Top: (3,7) Right-Top: (5,7) Right-Bottom: (5,5) Rectangle 2: translated 6 units to the right Left-Bottom: (9,5) Left-Top: (9,7) Right-Top: (11,7) Right-Bottom: (11,5)
True, rectangle contains (10,6)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started