Create a class that describes a rectangle in 2-D Space
· Start Point (x and y)
· End Point (x and y)
The class shall contain one constructor, one overloaded constructor which reads x1, y1, x2, y2 by passing them, and the following methods:
· SetStartPoint
Read x and y by passing parameters.
· SetEndPoint
Read x and y by passing parameters.
· GetStartPoint, GetEndPoint
class Point{ private double x,y; public Point(double x,double y){ this.x = x; this.y = y; } public double getX(){ return this.x; } public double getY(){ return this.y; } public String getXY(){ return "("+String.valueOf(this.x) +","+ String.valueOf(this.y)+")"; } } class Rectangle{ Point startPoint; Point endPoint; public Rectangle(){ } public Rectangle(double x1,double y1,double x2,double y2){ startPoint = new Point(x1,y1); endPoint = new Point(x2,y2); } public void setStartPoint(double x,double y){ startPoint = new Point(x, y); } public void setEndPoint(double x, double y){ endPoint = new Point(x,y); } public Point getStartPoint(){ return this.startPoint; } public Point getEndPoint(){ return this.endPoint; } public static void main(String args[]){ Rectangle r1 = new Rectangle(); r1.setStartPoint(1, 0); r1.setEndPoint(2, 2); System.out.println("Rectangle r1 : "); System.out.println("Start Point : "+r1.getStartPoint().getXY()); System.out.println("End Point : " + r1.getEndPoint().getXY()); Rectangle r2 = new Rectangle(1,2,3,4); System.out.println("\nRectangle r2 : "); System.out.println("Start Point : "+r2.getStartPoint().getXY()); System.out.println("End Point : " + r2.getEndPoint().getXY()); } }
Create a class that describes a rectangle in 2-D Space · Start Point (x and y)...
Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...
Implement the Point class (code for this up to the isHigher
method was discussed in the
lecture). The class has the following instance variables:
• x coordinate (an int)
• y coordinate (an int)
and the following methods:
• Constructor that sets the x and y coordinates
• Get and set methods
• Method equals if this point is equal to another point object
(if the x and y coordinates are the
same).
• Method isHigher if this point is...
Java Object Oriented Create a class that models a rectangle located in the first Cartesian quadrant. The class should store information about a rectangle such that it can be drawn in an X,Y cartesian coordinate system, including rectangles which are not aligned parallel to the X-Y axes, that is, they are oriented making an angle with the X axis. Your class should provide one constructor methods for specifying the rectangle The constructor should receive the rectangle area, the length of...
1. In IntelliJ create a new project called F1_2 2. In the Project window create a new Java package called F1_2. This can be done by right clicking on src and going to New ! Package. 3. In package lab1 2 create a class called Rectangle. This can be done by right clicking on the package and going to New ! Java Class 4. At the beginning of Rectangle.java add the line package lab1 2; 5. In Rectangle.java create a...
Create a BoxFigure class that inherits RectangleFigure class BoxFigure Class should contain:- Height instance field- Default constructor -- that calls the default super class constructor and sets the default height to 0- Overloaded constructor with three parameters (length, width and height) – that calls the two parameterized super class constructor passing in length and width passed and sets the height to passed height.- setDimension method with three parameters (length, width, height) – call the super class setDimension and pass in...
In Java please!
Problem You will be using the point class discussed in class to create a Rectangle class. You also need to have a driver class that tests your rectangle. Requirements You must implement the 3 classes in the class diagram below and use the same naming and data types. Following is a description of what each method does. Point Rectangle RectangleDriver - x: int - top Left: Point + main(args: String[) - y: int - width: int +...
Using the IST Linux system create the following Java command
line inheritance application Lab4. Create the following project
Java files: Point.java, Shape.java, Circle.java, Triangle.java,
Rectangle.java, and Lab4.java
Point.java will contain two coordinates x and y. This will be
reused to create point objects to draw all the shapes.
Shape.java will be the parent class and will contain a Point
type.
Circle.java, Triangle.java, Rectangle.java will all be children
of Shapes.java class
Each class (Circle, Triangle, Rectangle) will contain the
private class...
C++
Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...
Java code for the following inheritance hierarchy figure..
1. Create class Point, with two private
instance variables x and y that represented for the coordinates for
a point.
Provide constructor for initialising two instance variables.
Provide set and get methods
for each instance variable,
Provide toString method to return formatted
string for a point coordinates.
2. Create class Circle, its inheritance from
Point.
Provide a integer private
radius instance variable.
Provide constructor to
initialise the center coordinates and radius for...