Sunday 15 July 2012

Creating a rectangle with vectors and points in java? -


I have given an assignment to create a square that defines 2 points and then create a square that is given to vector Defines then create a square which defines a rectangular (4 vectors) before this assignment was given to me to calculate the length of a vector to create a point and vector square. I have 100% marks on that assignment, so I know that I can use that code to help me create this rectangle.

In this present assignment, make a rectangle square and calculate its circumference and area. I have spent some time in creating my rectangle class, but every time I feel that it looks correct, it throws the load of compiling errors.

Anyway this is my last code which is using to help me for the rectangular class:

Point class:

  public Square point {private double x; Private double y; Public point () {x = 0.0; Y = 0.0; } Public point (double A, double b) {x = a; Y = b; } Public Double GetV () {return x}} Public Double GetY () {return y;}}  

Vector class:

  public square vector { Private point P = new point (); Private point q = new point (); Public vector (Point A, Point B) {p = a; Q = b; } Public double giveLength () {double xDiff = q.getX () - p.getX (); Double yDiff = q.getY () - p.getY (); Return of Mathematics (SRD) ((xDiff * xDiff) + (yDiff * yDiff)); } Public Double giveLength2 () {Double x2Diff = p.getX2 () - q.getX2 (); Double y2Diff = p.getY2 () - q.getY2 (); Return Math.sqrt ((x2Diff * x2Diff) + (y2Diff * y2Diff)); }}  

Assignment 7 class:

  import java.util. *; Import java.math. *; Import java.io * *; Class assignment 7 {Public static zero main (string [] args throws exception {double x 1; Double Y1; Double X2; Double Y2; Point P1; Point P2; Vector V; Scanner = new scanner (System.in); System.out.println ("Please enter a filename:"); String filename = in.nextLine (); File inputfile = new file (file name); Scanner reader = new scanner (input file); While (reader.hasNext ()) {X1 = reader.nextDouble (); Y1 = Reader NXD double (); P1 = new point (x1, y1); X2 = Reader Nxt double (); Y2 = Reader NXD double (); P2 = new point (x2, y2); V = new vector (P1, P2); System.out.println ("X1" + X1 + "Length" + V.giveLength ()); }}}  

Input file format:

  xyxyxy  

Below is what my current rectangle looks square , But many of its constructor errors are to be thrown.

  square rectangle {private vector w = new vector (); Personal vector x = new vector (); Personal vector y = new vector (); Personal vector z = new vector (); Public Rectangle (Vector A, Vector B, Vector C, Vector D) {w = A; X = b; Y = c; Z = d; } Public double de premium () {double perimeter = ((w.giveLength () + x.giveLength2 ()) * 2); Return circumference; } Public Double Do Area () {Double Area = (w.giveLength () * y.giveLength2 ()); Return area; }}  

Thanks for helping in advance!

Please try the 4 vectors to get started here:

  Private vector w = new vector (); Personal vector x = new vector (); Personal vector y = new vector (); Personal vector z = new vector ();  

But you do not have a logic with no vector constructor!

There is no point in creating a non-digit vector. What you want to do, first read in the coordinates and set your 4 points, then after your points are determined, create 4 vectors from the points (well, 2 each).

Then ... announcements for this private below where your points are already set up, and put a pair of points in each group of each parenthesis.


No comments:

Post a Comment