Islamic Forum

## Recommended Posts

asslamualaikum,

can somebody please help me with this program, I have to create a program called ShapeShift which does simple calculations and manipulations of simple shapes expressed in two-dimensional co-ordinate geometry. The program is given a number of commnad line arguments which define a shape (circle, triangle or rectangle).

A circle has 3 arguments (2 more for OffSet values)

triangle has 6 arguments (2 more for OffSet values)

rectangle has 4 arguments (2 more for offset values)

the program then reports a standard output

* the details of the original shape - givning all the points

* the area na dperimeter of the shape

* and details of the shifted shape

these classes have been created

```
public class Circle
{

// Use the circle to find the centre and the radius.

private final Point Centre;

// Construct the two values

{
Centre = requiredCentre;
}

public double areaCircle()
{
} // areaCircle

public double Perimeter()
{
return (2 * Math.PI * Radius);
} //Perimeter
}
// Circle```

```
public class Point
{
// Two Coordinate values for each point
private final double CoordinateX;
private final double CoordinateY;

// Construct the two values
public Point(double requiredCoordinateX, double requiredCoordinateY)
{
CoordinateX = requiredCoordinateX;
CoordinateY = requiredCoordinateY;
}

// Get the X Coordinate
public double getXCoordinate()
{
return CoordinateX;
}

// Get Y Coordinate
public double getYCoordinate()
{
return CoordinateY;
}

// The layout, when demonstrating the two values.
public String toString()
{
return "(" + CoordinateX + "," + CoordinateY + ")";
} // String

// Calculate the moved coordinates, when added to OffSetX and OffSetY
public Point movedPoint(double OffSetX, double OffSetY)
{
return new Point (CoordinateX + OffSetX,
CoordinateY + OffSetY);
} //movedPoint

// Calculate the distance between two points
public double distance(Point other)
{
return Math.sqrt(Math.pow((CoordinateX - other.CoordinateX), 2) +
Math.pow((CoordinateY - other.CoordinateY), 2));
} // Distance calculated

} // Point```

```public class Rectangle
{
private final Point a;
private final Point b;

// Constructor Method
public Rectangle(Point requiredA, Point requiredB)
{
a = requiredA;
b = requiredB;
}

// Get point c for the third commnadline
public Point c()
{
return new Point(a.getXCoordinate(), b.getYCoordinate());
}// c

// Get point d for the forth commandline
public Point d()
{
return new Point(b.getXCoordinate(), a.getYCoordinate());
} //d

public double AreaRectangle()
{
return (a.distance(c()) * a.distance(d()));
}

public double PerimeterRectangle()
{
return  (2 * (a.distance(c())) + (a.distance(d())));
}

} // Rectangle```

```public class Triangle
{

// Triangle, has 8 values including 2 OffSet values.

private final Point TrianglePoint1;
private final Point TrianglePoint2;
private final Point TrianglePoint3;

// Constructor Method

public Triangle(Point requiredTrianglePoint1,
Point requiredTriagnlePoint2,
Point requiredTrianglePoint3)
{
TrianglePoint1 = requiredTrianglePoint1;
TrianglePoint2 = requiredTriagnlePoint2;
TrianglePoint3 = requiredTrianglePoint3;
}

public double PerimeterTriangle()
{
return (TrianglePoint1.distance(TrianglePoint2) +
TrianglePoint2.distance(TrianglePoint3) +
TrianglePoint3.distance(TrianglePoint1));
} // PerimeterTriangle

// Work and return the area of the triangle
public double AreaTriangle()
{
double semiPerimeter = (TrianglePoint1.distance(TrianglePoint2) +
TrianglePoint2.distance(TrianglePoint3) +
TrianglePoint3.distance(TrianglePoint1) / 2);

return Math.sqrt(semiPerimeter *
(semiPerimeter - TrianglePoint1.distance(TrianglePoint2)) *
(semiPerimeter - TrianglePoint2.distance(TrianglePoint3)) *
(semiPerimeter - TrianglePoint3.distance(TrianglePoint1)));
} // AreaTriangle

} //Triangle```

all complile except my main class, below!!

```public class ShapeShift
{

/* A program which performs simple calculations and manipulations of simple
shapes expressed in two-dimensional co-ordinate geometry.

The program will be given a set of command line arguments that define a
particular shape, the shapes are as follows, circle, triangle and rectangle.

The program will create the specified shape and also a similar one, where
each point has been shifted the X and Y offset
*/
public static void main (String[]args)
{
// To be valid there must be a minimum of 5 arguments, which are taken by the
// circle, the triangle will have 8 and the rectangle 6

if (args.length == 5 || args.length == 8 || args.length == 6)

switch (args.length)
{

case 5 : Point circleCentre = (Double.parseDouble(args),
Double.parseDouble(args))
Circle circle = new Circle(centreCircle, Radius)
double areaCircle = circle.areaCircle();
double Perimeter = circle.Perimeter();
double OffSetX = Double.parseDouble(args);
double OffSetY = Double.parseDouble(args);
Point shiftedPoint = circleCentre.movedPoint(OffSetX, OffSetY)
System.out.println("Circle (" + Point.toString() + ")");

case 8 : Point TrianglePoint1 = (Double.parseDouble(args).
Double.parseDouble(args))
Point TrianglePoint2 = (Double.parseDouble(args),
Double.parseDouble(args))
Point TrianglePoint3 = (Double.parseDouble(args),
Double.parseDouble(args))
Triangle triangle = new Triangle(TrianglePoint1,
TrianglePoint2,
TrianglePoint3)
double PerimeterTriangle = triangle.PerimeterTriangle();
double AreaTriangle = triangle.AreaTriangle();
double OffSetX = Double.parseDouble(args);
double OffSetY = Double.parseDouble(args);
Point shiftedPoint1 = TrianglePoint1.movedPoint(OffSetX, OffSetY)
Point shiftedPoint2 = TrianglePoint2.movedPoint(OffSetX, OffSetY)
Point shiftedPoint3 = TrianglePoint3.movedPoint(OffSetX, OffSetY)
System.out.println("Triangle (" + Point.toString() + ")");

case 6 : Point a = Double.parseDouble(args)
Point b = Double.parseDouble(args)
Point c = Double.parseDouble(args)
Point d = Double.parseDouble(args)
Rectangle rectangle = new Rectangle(a, b, c, d)
double AreaRectangle = rectangle.AreaRectangle();
double PerimeterRectangle = rectangle.PerimeterRectangle();
double OffSetX = Double.parseDouble(args);
double OffSetY = Double.parseDouble(args);
Point shiftedPointa = a.movedPoint(OffSetX, OffSetY)
Point shiftedPointb = b.movedPoint(OffSetX, OffSetY)
Point shiftedPointc = c.movedPoint(OffSetX, OffSetY)
Point shiftedPointd = d.movedPoint(OffSetX, OffSetY)
System.out.println("Rectangle (" + Point.toString() + ")");
else
{

// If incorrect commnadline arguments are entered, the following eror
// messages will be appear

System.out.println
("Usage: java ShapeShift x and y co-ordinates and offset values,");
System.out.println
("Where: x and y co-ordinates are double, and 2 offset values,");
System.out.println
("and: the number of entries depend on the shape, if circle 5" +
" entries, if triangle 8 entries and if square 6 entries.");
System.out.println("Please enter 5, 6 or 8 values");
} //else
} //if

/* Print out the final answer for each shape*/
private static void printAnswer(double area, double perimeter,
double OffSetX, double OffSetY)
{
System.out.println("has area " + area + ", perimeter " + perimeter +
"[##][/##]n" + "and when shifted by X Offset " + OffSetX +
" and Y Offset " + OffSetY + ", gives ");

} //main
} //class ShapeShift```

but there are some errors when I compile it, these are errors like } needed, and some more ; are needed, I cant say where coz I dont have Java at home I do at uni...but need some help please...!!

will be so grateful

walaikumsalam

##### Share on other sites asslamualaikum

I am done, Jazakhallah'Khairun anyway

walaikumsalam :D 