Hey Guys,
So I recently got a a project from my teacher.
Its on a shape.
/>/>/>/>
Great.
This is what Im working with
![Posted Image]()
Just a little background info.
We are to assume that a rhombus is created with its top and bottom corners at the same x coordinate, and its left and y corners at the same y coordinate
The point that defines the (x, y) coordinate of its top corner.
The length of its horizontal diagonal is the p
The length of its vertical diagonal is the q
Once weve got the 4 points, the length of its horizontal diagonal, and the length of its vertical diagonal,
we can calculate all the properties of the rhombus.
Now to the good stuff.
/>
I created three different classes:Rhombus,RhombusTester, and TestDriver.
Please read the comments
Instructions: In class Rhombus:
1. Implement the constructor with its 3 parameters (top point, horizontal length, and
vertical length), and declare and initialize the instance variables.
2. Implement accessor method getTopPoint, which takes no parameters and returns a
Point2D.Double.
Im having trouble understanding the return part, so i just put topPoint as the return.
Next,
Instructions:In class RhombusTester:
1. Implement method testRhombus, a void method with no parameters, and the
instance variable it needs to do its job.
In the methods body, display the expected and actual x, y values of the top point of the
rhombus.
- Note: class Point2D.Double defines accessor methods getX and getY.
2. Implement the constructor to initialize the instance variable.
Obviously Point2D.Double is not a type because when I tried to declare topPoint with type Point2D.Double it says its not a type. But to my instructor it is.
He insisted : To define a point in Java, use class Point2D.Double, which is documented at
http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Point2D.Double.html.
o For example, to create a Point2D.Double variable named topPoint at 4.0, 6.5:
topPoint = new Point2D.Double(4.0, 6.5);
I need a clear understanding, Im pretty puzzled.
Thanks,
sad ladyJava
So I recently got a a project from my teacher.
Its on a shape.
Great.
This is what Im working with

Just a little background info.
We are to assume that a rhombus is created with its top and bottom corners at the same x coordinate, and its left and y corners at the same y coordinate
The point that defines the (x, y) coordinate of its top corner.
The length of its horizontal diagonal is the p
The length of its vertical diagonal is the q
Once weve got the 4 points, the length of its horizontal diagonal, and the length of its vertical diagonal,
we can calculate all the properties of the rhombus.
Now to the good stuff.
I created three different classes:Rhombus,RhombusTester, and TestDriver.
Please read the comments
package edu.westga.rhombus.model;
import java.awt.geom.Point2D;
//Class defines a Rhombus with three different points. From points
//these points an (x,y) coordinate is calculated from the corners
//of the Rhombus
public class Rhombus {
//Instance variables represents three different points from the
//Rhombus. The top point, the point that defines the horziontal
//length and the point that defines the vertical length
Double topPoint;
Double hLength;
Double vLength;
public Rhombus(double topPoint, double hLength, double vLength)
{
}
public double getTopPoint()
{
return topPoint; // My instructor require I return a Point2D.Double
//Im not sure how I go about that.
}
}
Instructions: In class Rhombus:
1. Implement the constructor with its 3 parameters (top point, horizontal length, and
vertical length), and declare and initialize the instance variables.
2. Implement accessor method getTopPoint, which takes no parameters and returns a
Point2D.Double.
Im having trouble understanding the return part, so i just put topPoint as the return.
Next,
package edu.westga.rhombus.controller;
public class RhombusTester {
Double topPoint;
public RhombusTester()// Im pretty sure these needs a paramter
// My teacher used Point2D.Double as a
//type in his example, But below its not working.
{
topPoint= new Point2D.Double(4.0,6.5);//It gives an error
//saying Point2D.Double cant be
//resolved to a type
}
public void testRhombus()
{
System.out.println("The Expected Value of the top point is");
topPoint.getX();// It gives an error saying getX() is undefined for
//the type double
//topPointX= topPoint.getX();
}
}
Instructions:In class RhombusTester:
1. Implement method testRhombus, a void method with no parameters, and the
instance variable it needs to do its job.
In the methods body, display the expected and actual x, y values of the top point of the
rhombus.
- Note: class Point2D.Double defines accessor methods getX and getY.
2. Implement the constructor to initialize the instance variable.
Obviously Point2D.Double is not a type because when I tried to declare topPoint with type Point2D.Double it says its not a type. But to my instructor it is.
He insisted : To define a point in Java, use class Point2D.Double, which is documented at
http://docs.oracle.com/javase/7/docs/api/java/awt/geom/Point2D.Double.html.
o For example, to create a Point2D.Double variable named topPoint at 4.0, 6.5:
topPoint = new Point2D.Double(4.0, 6.5);
I need a clear understanding, Im pretty puzzled.
Thanks,
sad ladyJava