Question

Create a class that describes a rectangle in 2-D Space · Start Point (x and y)...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
 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()); } }

| java —-bash — 80x24 [Pratyushs-MacBook-Pro:java pthapli$ javac Rectangle.java [Pratyushs-MacBook-Pro:java pthapli$ java Rec

class Rectangle{ 19 20 21 Point startPoint; Point endPoint; 22 public Rectangle() { } public Rectangle(double x1, double y1,

= } Users > pthapll > Desktop > HomeworkLibing> Java > Rectangle.java > 5 Rectangle 1 class Point{ 2 private double x,y; 3 public P

Add a comment
Know the answer?
Add Answer to:
Create a class that describes a rectangle in 2-D Space · Start Point (x and y)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Making a rectangle class in java write a simple class that will represent a rectangle. Later...

    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...

    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....

    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...

    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...

    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...

    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...

    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...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    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...

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT