A constructor that constructs a rectangle2d

Assignment Help C/C++ Programming
Reference no: EM13165010

Write a class called Rectangle2D to represent a rectangle in the plane (2 dimensional space). The class
must contain:

  • Four points p1, p2, p3 and p4 of type MyPoint.
  • Getter methods for the four points.
  • A method LinkedList<MyPoint> getVertices() that returns a list of the vertices of the

rectangle (so a list of the points).

  • A constructor that constructs a Rectangle2D with specified points as coordinates.
  • A no-argument constructor that creates the rectangle with points (0, 0), (5, 5) and (0, 5) and

(5,0) - this constructor must call your previous constructor.

  • A non-static method double getPerimeterLength() that returns the length of the perimeter of a

rectangle.

Write a main class as follows:
Rectangle2D rect = new Rectangle2D();
double len = rect.getPerimeterLength();

Here is the code for the MyPoint class:

public class MyPoint
{
   private double x;
   private double y;
  
   public MyPoint(double x, double y)
   {
       super();
       this.x = x;
       this.y = y;
   }
  
   public void setX(double x) {
       this.x = x;
   }

   public void setY(double y) {
       this.y = y;
   }

   public MyPoint()
   {
       this(0,0);
      
   }
   public double getX()
   {
       return x;
   }

   public double getY()
   {
       return y;
   }

   public double getDistance(MyPoint P)
   {
       return Math.sqrt(Math.pow(this.x-P.getX(), 2) + Math.pow(this.y-P.getY(), 2));
   }

Reference no: EM13165010

Questions Cloud

How many grams na3po4 of will be needed : How many grams Na3PO4 of will be needed to produce 475 mL of a solution that has a concentration of Na+ ions of 0.900 M ?
What mass of urea is produced per minute by this reaction : Ammonia gas at 223°C and 90. atm flows into a reactor at a rate of 550. L/min. Carbon dioxide at 223°C and 47 atm flows into the reactor at a rate of 600. L/min. What mass of urea is produced per minute by this reaction assuming 100% yield?
The hydrogen atoms have been replaced by another substituent : Many common weak bases are derivatives of NH3, where one or more of the hydrogen atoms have been replaced by another substituent.
According to social contract theory : According to social contract theory, the purpose of the state (or government) is to enforce essential rules of social living; however, social contract theorists make an exception for business because the greater good is best served when commercial tr..
A constructor that constructs a rectangle2d : A constructor that constructs a Rectangle2D with specified points as coordinates.A no-argument constructor that creates the rectangle with points (0, 0), (5, 5) and (0, 5) and
Explain why triethylamine is a weaker base : Explain why triethylamine is a weaker base than dimethylamine or methylamine.
Write a program to track hourly employee arrival departure : THE JAVA SOURCE CODEWILL AWARD AN ADDITIONAL 1,500 POINTS TO PERSON WITH THE BEST ANSWER (you will be directed to another one of my previous, unanswered questions.)A company hires you to write a program to track hourly employee arrival and departure ..
What is the number of mole equivalents of h2 produced : what is the number of mole equivalents of H2 produced by the reaction of 1 mole equivalent of Mg (m) with H2SO4 (aq)?
Moral to treat lawbreakers : According to your assigned reading, it is moral to treat lawbreakers who harm others and don't keep their agreements differently from citizens who abide by the law and social contract because

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Problems on oops

Problems on OOPS

  Users to input two forces by their components

write a programm to ask users to input two forces by their components of (Fx1,Fy1) and (Fx2,Fy2) from the keyboard.call twice the function to display both magnitude and direction angle of two forces on the screen.add two forces and display both magni..

  Create a program that maintains the required book catalog

Create a program that maintains the required book catalog for the circulation desk of a library.

  Write the output of the program

Design a C++ program that will interactively prompt for and read the name of the input file interactively prompt for and read the name of a file to write the output of the program to write the following to the specified output file your name, sect..

  Write function to accept character array

Write down the C++ function which will accept the character array of at most 30 cells. Your function must return true if string and its reverse are identical;

  Attribute information about an array of floating point

Write a program that contains a main function and three other functions that will return various attribute information about an array of floating point

  Write a program that asks the user to enter the names of 3

Write a program that asks the user to enter the names of three salesmen. The program should thenaccept the sales produced for salesman for each quarter of the year. Display the name, and the totalsales amount, of each salesman.

  Write a recursive and iterative versions of binary search

in C++ write a recursive and iterative versions of binary search and compare their run times using the array a[i]=i, i=0,..., n-1

  Class to act as a generic array

Create a class to act as a generic array (i.e. the user will be able to choose the data type to be stored by passing the appropriate template argument.

  Using array subscript notation

Using array subscript notation, base/offset notation with the array name as the pointer, array notation with  vPtr , and pointer/offset notation with  vPtr , add 3 to the value in the 3 rd element and display that number. (Do not modify the value in ..

  Write program to input series of hourly temperatures

Create and write a c++ program which inputs series of 24 hourly temperatures from file, and outputs bar chart (using stars) of temperatures for the day.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd