How to create a class in java that contains get and set methods for the double variables x,y,height,width where x and y represent the center point of your rectangle and width and height epresent the width and height of your rectangle, a no argument constructor that sets x to 0, y to 0, width to 1, and height to 1 that output your name, a constructor that has x, y, width, and height input parameters, for example If the x or y input parameters are less than 0.0, set them to be 0.0 and If the width or height input parameters are less than 1.0, set them to be 1.0, a method called myTop that returns the y coordinate of the top of the rectangle (y + 0.5*height), a method called myBottom that returns the y coordinate of the bottom of the rectangle (y – 0.5*height), a method called myLeft that returns the x coordinate of the left side of the rectangle (x – 0.5*width), a method called myRight that returns the x coordinate of the left side of the rectangle (x + 0.5*width), a method getArea that returns the area of the rectangle (width * height), a method called getPerimeter that returns the perimeter of the rectangle (2 * width + 2 * height), and a method called contains(double inX, double inY) that returns true if the point (inX,inY) is inside the rectangle and false otherwise, then test the class by create a class with a main method that creates instances of your class and calling all the constructors and method? For example, assume a rectangle was created with x=2.0, y=1.0, width=1.0, and height=2.0 getX would return 2.0 getY would return 1.0 getWidth would return 1.0 getHeight would return 2.0 myTop would return 2.0 myBottom would return 0.0 myLeft would return 1.5 myRight would return 2.5 getArea would return 2.0 getPerimeter would return 6.0 contains(1.75,0.9) would return true contains(2.5,2.25) would return false
How to create a class in java that contains get and set methods for the double variables x,y,height,width where x and y represent the center point of your rectangle and width and height epresent the width and height of your rectangle, a no argument constructor that sets x to 0, y to 0, width to 1, and height to 1 that output your name, a constructor that has x, y, width, and height input parameters, for example If the x or y input parameters are less than 0.0, set them to be 0.0 and If the width or height input parameters are less than 1.0, set them to be 1.0, a method called myTop that returns the y coordinate of the top of the rectangle (y + 0.5*height), a method called myBottom that returns the y coordinate of the bottom of the rectangle (y – 0.5*height), a method called myLeft that returns the x coordinate of the left side of the rectangle (x – 0.5*width), a method called myRight that returns the x coordinate of the left side of the rectangle (x + 0.5*width), a method getArea that returns the area of the rectangle (width * height), a method called getPerimeter that returns the perimeter of the rectangle (2 * width + 2 * height), and a method called contains(double inX, double inY) that returns true if the point (inX,inY) is inside the rectangle and false otherwise, then test the class by create a class with a main method that creates instances of your class and calling all the constructors and method?
For example, assume a rectangle was created with x=2.0, y=1.0, width=1.0, and height=2.0
getX would return 2.0
getY would return 1.0
getWidth would return 1.0
getHeight would return 2.0
myTop would return 2.0
myBottom would return 0.0
myLeft would return 1.5
myRight would return 2.5
getArea would return 2.0
getPerimeter would return 6.0
contains(1.75,0.9) would return true
contains(2.5,2.25) would return false
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 5 images