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

  Program that will read in such an array

Write a program that will read in such an array, and repeatedly prints it so the user can select the direction in which to move next. The user's requested move can prompt a number of responses

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Program that read in from the key board a string

Write a complete C++ program that read in from the key board a string and convert all letters in the string to upper cases. You are not allowed to use toupper function.

  Write and test c program which outputs waveform

Write and test a C program which outputs waveform which switches from 10.0 kHz with a 50% duty cycle to 25.0 kHz with a 5% duty cycle every 5 seconds.

  When given a c-string reference and a character

Write a program that implements and tests the following functions for use with C-strings (you may assume that  input obtained by the program is limited to a maximum of 80 characters):

  Design and implement a library system

Design and implement a library system that does the following: ? Takes details of a student/library users: first name, last name, other names, user ID number, and nationality.

  Create a c++ console application

Objective: Create a C++ console application that will model the characteristics of a resistor. Create a multifile project. Create and add to the project an h file containing the resistor-class definition. Create and add to the project a cpp file cont..

  Code to implement a staque

Write a C++ code to implement a Staque. Since the data structure is all about inserting and deleting numbers, it would be a good option to use a linked list to implement Staque.

  Write a program that reads numbers

Write a C++ program that reads N positive numbers from the keyboard, calculates and shows the smallest number of all numbers

  Const int num_years

How do you get this program to get both player input and then display results(As described on bottom) #include  const int NUM_YEARS=15;//The number of years const int NAME_SIZE=32;//The max size of the player name string

  Change this code to read in strings from a text file

code takes in a string from a user, checks if the paranthesis are ballanced (as defined by my class) and also returns the variable from my line (also from my class). All like to change this code to read in strings from a text file (each line is a str..

  Draws a single level for a "rogue­like" computer game

You will write a program that draws a single level for a "Rogue­like" computer game. The program will parse a line of input text from an input file (room.txt), use the parsed text to determine the shape of the room and its contents and then draw the ..

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