У меня возникают проблемы с назначением, в котором мы должны построить 5 классов для создания программы, которая выполняет простые вычисления и манипуляции с простыми формами, выраженными в 2D-геометрии.Ошибка Java при попытке скомпилировать
Сначала он просит пользователя выбрать форму, из трех вариантов. Затем он запрашивает детали формы. Круг задается заданием координаты X и затем Y ее центра, за которым следует его радиус. Треугольник задается указанием координат X и Y каждой из трех угловых точек. Прямоугольник определяется заданием координат X и Y двух его диагонально противоположных угловых точек.
После этих данных пользователю предлагается указать смещение X и смещение по Y.
Программа создает указанную форму, а также аналогичную, , в которой каждая точка смещена смещениями X и Y.
Затем программа сообщает о стандартном выходе. Детали оригинальной формы - давая все точки (один, три или четыре), а для круга - радиус. Площадь и периметр формы. Детали сдвинутой формы.
В 5 классов должны быть ShapeShift
, Circle
, Triangle
, Point
и Rectangle
.
Мой код до сих пор выглядит следующим образом:
Прямоугольник
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 areaOfRectangle()
{
return (a.distance(c()) * a.distance(d()));
}
public double perimeterOfRectangle()
{
return (2 * (a.distance(c())) + (a.distance(d())));
}
} // Rectangle
Треугольник
public class Triangle
{
// Triangle, has 8 values including 2 shift 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 perimeterOfTriangle()
{
return (TrianglePoint1.distance(TrianglePoint2) +
TrianglePoint2.distance(TrianglePoint3) +
TrianglePoint3.distance(TrianglePoint1));
} // PerimeterTriangle
// Work and return the area of the triangle
public double areaOfTriangle()
{
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
Круг
public class Circle
{
// Use the circle to find the centre and the radius.
private final Point centre;
private final double radius;
// Construct the two values
public Circle(Point requiredCentre, double requiredRadius)
{
centre = requiredCentre;
radius = requiredRadius;
}
public double areaOfCircle()
{
return (Math.PI * (Math.pow(radius, 2)));
} // areaOfCircle
public double perimeterOfCircle()
{
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 xShift and yShift
public Point shift(double xShift, double yShift)
{
return new Point (coordinateX + xShift,
coordinateY + yShift);
} //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
Shapeshift
import java.util.Scanner;
public class ShapeShift
{
// A scanner to interact with the user.
private static Scanner inputScanner = new Scanner(System.in);
// Helper method to read a point from the input.
public static Point inputPoint(String prompt)
{
System.out.print(prompt);
double x = inputScanner.nextDouble();
double y = inputScanner.nextDouble();
return new Point(x, y);
} // inputPoint
// The X and Y amount to shift the first shape to get the second.
public static double xShift, yShift;
public ShapeShift(double shiftX, double shiftY)
{
xShift = shiftX;
yShift = shiftY;
}
// Helper method to read the X and Y shifts.
private static void inputXYShifts()
{
System.out.print("Enter the offset as X Y: ");
double xShift = inputScanner.nextDouble();
double yShift = inputScanner.nextDouble();
} // inputXYShifts
// The main method.
public static void main(String[] args)
{
// Obtain shape choice.
System.out.print("Choose circle (1), triangle (2), rectangle (3): ");
int shapeChoice = inputScanner.nextInt();
// Process the shape based on the choice.
switch (shapeChoice)
{
// Circle.
case 1:
Point centre = inputPoint("Enter the centre as X Y: ");
System.out.print("Enter the radius: ");
double radius = inputScanner.nextDouble();
Circle originalCircle = new Circle(centre, radius);
inputXYShifts();
Circle shiftedCircle = originalCircle.shift(xShift, yShift);
System.out.println();
System.out.println(originalCircle);
System.out.println("has area " + originalCircle.areaOfCircle()
+ ", perimeter "
+ originalCircle.perimeterOfCircle());
System.out.println("and when shifted by X offset " + xShift
+ " and Y offset " + yShift + ", gives");
System.out.println(shiftedCircle);
break;
// Triangle.
case 2:
Point pointA = inputPoint("Enter point A as X Y: ");
Point pointB = inputPoint("Enter point B as X Y: ");
Point pointC = inputPoint("Enter point C as X Y: ");
Triangle originalTriangle = new Triangle(pointA, pointB, pointC);
inputXYShifts();
Triangle shiftedTriangle = originalTriangle.shift(xShift, yShift);
System.out.println();
System.out.println(originalTriangle);
System.out.println("has area " + originalTriangle.areaOfTriangle()
+ ", perimeter "
+ originalTriangle.perimeterOfTriangle());
System.out.println("and when shifted by X offset " + xShift
+ " and Y offset " + yShift + ", gives");
System.out.println(shiftedTriangle);
break;
// Rectangle.
case 3:
Point diag1End1 = inputPoint("Enter one corner as X Y: ");
Point diag1End2 = inputPoint("Enter opposite corner as X Y: ");
Rectangle originalRectangle = new Rectangle(diag1End1, diag1End2);
inputXYShifts();
Rectangle shiftedRectangle = originalRectangle.shift(xShift, yShift);
System.out.println();
System.out.println(originalRectangle);
System.out.println("has area " + originalRectangle.areaOfRectangle()
+ ", perimeter "
+ originalRectangle.perimeterOfRectangle());
System.out.println("and when shifted by X offset " + xShift
+ " and Y offset " + yShift + ", gives");
System.out.println(shiftedRectangle);
break;
// Bad choice.
default:
System.out.println("That wasn't 1, 2 or 3!");
break;
} // switch
} // main
} // class ShapeShift
Все классы компилировать кроме ShapeShift
класса.
я получаю следующие 3 ошибки:
ShapeShift.java:78: error: cannot find symbol
Circle shiftedCircle = originalCircle.shift(xShift, yShift);
symbol: method shift(double,double)
ShapeShift.java:96: error: cannot find symbol
Triangle shiftedTriangle = originalTriangle.shift(xShift, yShift);
symbol: method shift(double,double)
ShapeShift.java:113: error: cannot find symbol
Rectangle shiftedRectangle = originalRectangle.shift(xShift, yShift);
symbol: method shift(double,double)
Я смотрел на это так долго, и был бы очень признателен свежий набор глаза. Заранее благодарю всех, кто может помочь!
Это почти то, что он говорит: Круг, Треугольник и Прямоугольник не имеют метода сдвига ... – assylias