У меня возникли проблемы с правильной работой TestPolygon.java. «// Конструктор, который создает четыре полигона с любым значением, не равным значению defualt или друг другу. Polygon [] P_array = {новый многоугольник (10,5.0,1.0.3.0), новый многоугольник (6,3,2) , 5), новый Polygon (4,11,4,3), новый Polygon (5,12,6,7)}; строка моего кода продолжает возвращаться с ошибкой для каждого нового заявления, говорящего, что «нет подходящего конструктора найдено Polygon (междунар, двойного, двойного, двойного). Фото прилагаются.Не найдено подходящего конструктора для
/* File: Polygon.java
* Author: Darren Pirtle Jr.
* Date: November 16, 2016
* Purpose: Design a Java class
* named Polygon
*/
import java.lang.Math;
public class Polygon {
private int numSides;
private double sideLength;
private double xCoord;
private double yCoord;
private double apothem;
private double perimeter;
//Constructor that creates a Polygon using the defaults
public Polygon(){
numSides = 4;
sideLength = 10.0;
xCoord = 0.0;
yCoord = 0.0;
apothem = 5.0;
}
//Constructor that uses the specified numbers
public Polygon(int s,double sL,double x,double y,double a, double p){
setNumSides(s);
setSideLength(sL);
setXCoord(x);
setYCoord(y);
setApothem(a);
}
// A getArea() method that returns a double value for the area of the polygon
public double getArea() {
return .5*apothem*perimeter;
}
// Getter and setter for all data fields
public int setNumSides(int s){
numSides = s;
return numSides;
}
public double setSideLength(double sL){
sideLength = sL;
return sideLength;
}
public double setXCoord(double x){
xCoord = x;
return xCoord;
}
public double setYCoord(double y){
yCoord = y;
return yCoord;
}
public double setApothem(double a){
apothem = a;
return apothem;
}
public double setPerimeter(double p){
perimeter = p;
return perimeter;
}
public int getNumSides() {
return numSides;
}
public double getSideLength() {
return sideLength;
}
public double getXCoord() {
return xCoord;
}
public double getYCoord() {
return yCoord;
}
public double getApothem() {
return apothem;
}
public double getPerimeter() {
return perimeter;
}
//A toString() that displays the values in string format
public String toString(){
return "("+numSides+", "+String.format("%.1f",sideLength)+", "+String.format("%.1f",xCoord)+", "+String.format("%.1f",yCoord)+")";
}
}
/* File: Polygon.java
* Author: Darren Pirtle Jr.
* Date: November 16, 2016
* Purpose: Design a Java class
* named Polygon
*/
//Import necessary packages
import java.util.Scanner;
import java.text.DecimalFormat;
import java.lang.Math;
class TestPolygon{
public static void main(String[] args){
//Constructor that creates one polygon with no argument
Polygon P = new Polygon();
//Constructor that creates four polygons with any value that are not equal to the defualt value or to each other
Polygon[] P_array = {new Polygon(10,5.0,1.0,3.0), new Polygon(6,3,2,5), new Polygon(4,11,4,3), new Polygon(5,12,6,7)};
//Constructor that calls all methods and displays results
System.out.println("toString() results: "+P);
System.out.println("getNumSides() results: "+ P.getNumSides());
System.out.println("getSideLength() results: "+ P.getSideLength());
System.out.println("getXCoord() results: "+ P.getXCoord());
System.out.println("getYCoord() results: "+ P.getYCoord());
System.out.println("getPerimeter() results: "+ P.getPerimeter());
System.out.println("setNumSides(4) results: "+ P.setNumSides(4));
System.out.println("setSideLength(3.0) results: "+ P.setSideLength(3.0));
System.out.println("setXCoord(2.0) results: "+ P.setXCoord(2));
System.out.println("setYCoord(2.0) results: "+ P.setYCoord(2));
for(int i=0; i<P_array.length; i++)
{
System.out.println("toString() results: "+P_array[i]);
System.out.println("getNumSides() results: "+ P_array[i].getNumSides());
System.out.println("getSideLength() results: "+ P_array[i].getSideLength());
System.out.println("getXCoord() results: "+ P_array[i].getXCoord());
System.out.println("getYCoord() results: "+ P_array[i].getYCoord());
System.out.println("getPerimeter() results: "+ P_array[i].getPerimeter());
System.out.println("setNumSides(4) results: "+ P_array[i].setNumSides(4));
System.out.println("setSideLength(3.0) results: "+ P_array[i].setSideLength(3.0));
System.out.println("setXCoord(2.0) results: "+ P_array[i].setXCoord(2));
System.out.println("setYCoord(2.0) results: "+ P_array[i].setYCoord(2));
}
}
}
сообщение об ошибке кажется довольно очевидным для меня. Конструктор Polygon() принимает int и 5 удваивается. Вы пытаетесь использовать конструктор, который принимает int и _4_ удваивает. Вероятно, крошечное исследование могло пройти долгий путь. – rmlan
Какой конструктор вы пытаетесь вызвать с помощью 'new Polygon (10, 5.0, 1.0, 3.0)'? Сравните ожидаемое количество аргументов с количеством аргументов, которые вы фактически предоставляете. Они совпадают? – Pshemo
я сделал изучение. Причина, по которой я писал здесь, - это то, что мне нужна помощь, потому что я ничего не нашел. Спасибо за грубый комментарий и помощь, хотя! – DarrenPJr