java中我的ShapeApp存在问题

java中我的ShapeApp存在问题,java,class,inheritance,interface,Java,Class,Inheritance,Interface,我得到下面的错误,这些是我的类 形状类别: public abstract class Shape implements Triangle{ protected static final double DEFAULT_SIZE = (double) 1.0; protected static final String DEFAULT_NAME = "Unknown"; private String shapeName; public Shape(){ this.shapeNa

我得到下面的错误,这些是我的类

形状类别:

public abstract class Shape implements Triangle{

 protected static final double DEFAULT_SIZE = (double) 1.0;
 protected static final String DEFAULT_NAME = "Unknown";
 private String shapeName;

 public Shape(){
    this.shapeName = DEFAULT_NAME;
 }

 public Shape(String name) {
    setShapeName(name);

 }

 protected void setShapeName(String name) {
 if( name.trim().length() == 0 )
     shapeName = DEFAULT_NAME;
 else
     shapeName = new String ( name );

 }

 public String getShapeName() {
    //name
 return shapeName;

 }



public abstract double getSurfaceArea();

public abstract double getPerimeter();


public String toString{
    return String.format("%s %s\nshape name: %s",getShapeName());
}
}
public class Rectangle extends Shape implements Triangle {



private double length;
private double heigth;

public Rectangle() {
    super("Rectangle");
    setLength( super.DEFAULT_SIZE );
    setHeight( Shape.DEFAULT_SIZE );

}

public Rectangle(double theLength, double theHeight ){
    super("Rectangle");
    if ( theLength < 0 )
        setLength( Shape.DEFAULT_SIZE );
    else setLength( theLength );

    if ( theHeight < 0)
        setHeight( Shape.DEFAULT_SIZE );
    else setHeight( theHeight );
}



public double getSurfaceArea() {
    return this.length * this.heigth;
}

public double getPeremeter() {
    return 2 * this.length + 2 * this.length;

}

public double getLength(){
    return this.length;
}

public double getHeight(){
    return  this.heigth;
}

public void setLength( double theLength ){
    if ( theLength <= 0 )
        return;
    this.length = theLength;
}

public void setHeight( double theHeight ){
    if (theHeight <= 0 )
        return;
    this.heigth = theHeight;

}

public String toString(){
    return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                      "Rect Surface Area ", "Rect Peremeter", getSurfaceArea(), getPeremeter());
}

 public double getSizeAmount(){

}

   }
public class Circle extends Shape {
private double radius;

public Circle( double theRadius ){
    super( "Circle" );
    if ( theRadius <= 0.0 )
        setRadius( Shape.DEFAULT_SIZE );
    else
        setRadius( theRadius );
}

public Circle(String string, String string2, String string3, String string4) {
    // TODO Auto-generated constructor stub
}

public double getSurfaceArea(){

    return this.radius * this.radius * Math.PI;
}

public double getPeremeter(){
    ;
    return 2 * this.radius + Math.PI;
}

public double getRadius(){
    return this.radius;

}

public void setRadius( double theRadius ) {
    if( theRadius <= 0 )
        return;
    this.radius = theRadius;
}

@Override
public double getPerimeter() {
    // TODO Auto-generated method stub
    return 0;

     public double getSizeAmount(){

     }

     public String toString(){
         return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                  "Circle Surface Area ", "Circle Peremeter", getSurfaceArea(), getPeremeter());
     }
}
   }
//triangle interface decleration
public interface Triangle {



double getSizeAmount(); //calculate sizes of triangle; no implementation

    }//end interface triangle
    import javax.swing.JOptionPane;




    public class ShapeApp {

//public static void main(String args[])
public static void main(String[] args) {

    Triangle triangleObjects[] = new Triangle[ 4 ];

    triangleObjects[ 0 ] = new Rectangle("3.5", "4.6","42");
    triangleObjects[ 1 ] = new Rectangle("3", "2","34");
    triangleObjects[ 2 ] = new Circle("Circle", "Rectangle","0808","0808");
    triangleObjects[ 3 ] = new Circle("Circle","Rectangle","2334","2423");

    System.out.println( "List of all Shapes:\n" );

    for( Triangle currentTriangle : triangleObjects ){

        System.out.printf("%s \n%s: $%,.2f\n\n",
                currentTriangle.toString(),
                "ovo testiramo", currentTriangle.getSizeAmount());

    }


}

}
矩形类:

public abstract class Shape implements Triangle{

 protected static final double DEFAULT_SIZE = (double) 1.0;
 protected static final String DEFAULT_NAME = "Unknown";
 private String shapeName;

 public Shape(){
    this.shapeName = DEFAULT_NAME;
 }

 public Shape(String name) {
    setShapeName(name);

 }

 protected void setShapeName(String name) {
 if( name.trim().length() == 0 )
     shapeName = DEFAULT_NAME;
 else
     shapeName = new String ( name );

 }

 public String getShapeName() {
    //name
 return shapeName;

 }



public abstract double getSurfaceArea();

public abstract double getPerimeter();


public String toString{
    return String.format("%s %s\nshape name: %s",getShapeName());
}
}
public class Rectangle extends Shape implements Triangle {



private double length;
private double heigth;

public Rectangle() {
    super("Rectangle");
    setLength( super.DEFAULT_SIZE );
    setHeight( Shape.DEFAULT_SIZE );

}

public Rectangle(double theLength, double theHeight ){
    super("Rectangle");
    if ( theLength < 0 )
        setLength( Shape.DEFAULT_SIZE );
    else setLength( theLength );

    if ( theHeight < 0)
        setHeight( Shape.DEFAULT_SIZE );
    else setHeight( theHeight );
}



public double getSurfaceArea() {
    return this.length * this.heigth;
}

public double getPeremeter() {
    return 2 * this.length + 2 * this.length;

}

public double getLength(){
    return this.length;
}

public double getHeight(){
    return  this.heigth;
}

public void setLength( double theLength ){
    if ( theLength <= 0 )
        return;
    this.length = theLength;
}

public void setHeight( double theHeight ){
    if (theHeight <= 0 )
        return;
    this.heigth = theHeight;

}

public String toString(){
    return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                      "Rect Surface Area ", "Rect Peremeter", getSurfaceArea(), getPeremeter());
}

 public double getSizeAmount(){

}

   }
public class Circle extends Shape {
private double radius;

public Circle( double theRadius ){
    super( "Circle" );
    if ( theRadius <= 0.0 )
        setRadius( Shape.DEFAULT_SIZE );
    else
        setRadius( theRadius );
}

public Circle(String string, String string2, String string3, String string4) {
    // TODO Auto-generated constructor stub
}

public double getSurfaceArea(){

    return this.radius * this.radius * Math.PI;
}

public double getPeremeter(){
    ;
    return 2 * this.radius + Math.PI;
}

public double getRadius(){
    return this.radius;

}

public void setRadius( double theRadius ) {
    if( theRadius <= 0 )
        return;
    this.radius = theRadius;
}

@Override
public double getPerimeter() {
    // TODO Auto-generated method stub
    return 0;

     public double getSizeAmount(){

     }

     public String toString(){
         return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                  "Circle Surface Area ", "Circle Peremeter", getSurfaceArea(), getPeremeter());
     }
}
   }
//triangle interface decleration
public interface Triangle {



double getSizeAmount(); //calculate sizes of triangle; no implementation

    }//end interface triangle
    import javax.swing.JOptionPane;




    public class ShapeApp {

//public static void main(String args[])
public static void main(String[] args) {

    Triangle triangleObjects[] = new Triangle[ 4 ];

    triangleObjects[ 0 ] = new Rectangle("3.5", "4.6","42");
    triangleObjects[ 1 ] = new Rectangle("3", "2","34");
    triangleObjects[ 2 ] = new Circle("Circle", "Rectangle","0808","0808");
    triangleObjects[ 3 ] = new Circle("Circle","Rectangle","2334","2423");

    System.out.println( "List of all Shapes:\n" );

    for( Triangle currentTriangle : triangleObjects ){

        System.out.printf("%s \n%s: $%,.2f\n\n",
                currentTriangle.toString(),
                "ovo testiramo", currentTriangle.getSizeAmount());

    }


}

}
主类:

public abstract class Shape implements Triangle{

 protected static final double DEFAULT_SIZE = (double) 1.0;
 protected static final String DEFAULT_NAME = "Unknown";
 private String shapeName;

 public Shape(){
    this.shapeName = DEFAULT_NAME;
 }

 public Shape(String name) {
    setShapeName(name);

 }

 protected void setShapeName(String name) {
 if( name.trim().length() == 0 )
     shapeName = DEFAULT_NAME;
 else
     shapeName = new String ( name );

 }

 public String getShapeName() {
    //name
 return shapeName;

 }



public abstract double getSurfaceArea();

public abstract double getPerimeter();


public String toString{
    return String.format("%s %s\nshape name: %s",getShapeName());
}
}
public class Rectangle extends Shape implements Triangle {



private double length;
private double heigth;

public Rectangle() {
    super("Rectangle");
    setLength( super.DEFAULT_SIZE );
    setHeight( Shape.DEFAULT_SIZE );

}

public Rectangle(double theLength, double theHeight ){
    super("Rectangle");
    if ( theLength < 0 )
        setLength( Shape.DEFAULT_SIZE );
    else setLength( theLength );

    if ( theHeight < 0)
        setHeight( Shape.DEFAULT_SIZE );
    else setHeight( theHeight );
}



public double getSurfaceArea() {
    return this.length * this.heigth;
}

public double getPeremeter() {
    return 2 * this.length + 2 * this.length;

}

public double getLength(){
    return this.length;
}

public double getHeight(){
    return  this.heigth;
}

public void setLength( double theLength ){
    if ( theLength <= 0 )
        return;
    this.length = theLength;
}

public void setHeight( double theHeight ){
    if (theHeight <= 0 )
        return;
    this.heigth = theHeight;

}

public String toString(){
    return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                      "Rect Surface Area ", "Rect Peremeter", getSurfaceArea(), getPeremeter());
}

 public double getSizeAmount(){

}

   }
public class Circle extends Shape {
private double radius;

public Circle( double theRadius ){
    super( "Circle" );
    if ( theRadius <= 0.0 )
        setRadius( Shape.DEFAULT_SIZE );
    else
        setRadius( theRadius );
}

public Circle(String string, String string2, String string3, String string4) {
    // TODO Auto-generated constructor stub
}

public double getSurfaceArea(){

    return this.radius * this.radius * Math.PI;
}

public double getPeremeter(){
    ;
    return 2 * this.radius + Math.PI;
}

public double getRadius(){
    return this.radius;

}

public void setRadius( double theRadius ) {
    if( theRadius <= 0 )
        return;
    this.radius = theRadius;
}

@Override
public double getPerimeter() {
    // TODO Auto-generated method stub
    return 0;

     public double getSizeAmount(){

     }

     public String toString(){
         return String.format("%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
                  "Circle Surface Area ", "Circle Peremeter", getSurfaceArea(), getPeremeter());
     }
}
   }
//triangle interface decleration
public interface Triangle {



double getSizeAmount(); //calculate sizes of triangle; no implementation

    }//end interface triangle
    import javax.swing.JOptionPane;




    public class ShapeApp {

//public static void main(String args[])
public static void main(String[] args) {

    Triangle triangleObjects[] = new Triangle[ 4 ];

    triangleObjects[ 0 ] = new Rectangle("3.5", "4.6","42");
    triangleObjects[ 1 ] = new Rectangle("3", "2","34");
    triangleObjects[ 2 ] = new Circle("Circle", "Rectangle","0808","0808");
    triangleObjects[ 3 ] = new Circle("Circle","Rectangle","2334","2423");

    System.out.println( "List of all Shapes:\n" );

    for( Triangle currentTriangle : triangleObjects ){

        System.out.printf("%s \n%s: $%,.2f\n\n",
                currentTriangle.toString(),
                "ovo testiramo", currentTriangle.getSizeAmount());

    }


}

}
这就是我得到的错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The constructor Rectangle(String, String, String) is undefined
The constructor Rectangle(String, String, String) is undefined

at ShapeApp.main(ShapeApp.java:14)

错误信息非常清楚:

The constructor Rectangle(String, String, String) is undefined

at ShapeApp.main(ShapeApp.java:14)
您正在使用3个参数创建矩形对象

 new Rectangle("3.5", "4.6","42");
但是您的矩形类只有两个构造函数

1) 参数为零的构造函数2)参数为2的构造函数


您需要在
Rectangle
类中添加带有3个参数的构造函数(或)将对象创建更改为两个参数的构造函数。

错误消息非常清楚:

The constructor Rectangle(String, String, String) is undefined

at ShapeApp.main(ShapeApp.java:14)
您正在使用3个参数创建矩形对象

 new Rectangle("3.5", "4.6","42");
但是您的矩形类只有两个构造函数

1) 参数为零的构造函数2)参数为2的构造函数


您需要在
Rectangle
类中添加带有3个参数的构造函数(或)将对象创建更改为两个参数的构造函数。

在被(相对简单的)错误弄糊涂之前,您怎么会得到那么多的代码?你的学习伙伴会给你这么多的作业吗?你怎么会在被那个(相对简单的)错误弄糊涂之前得到那么多的代码?这是你的学习伙伴给你的作业量吗?谢谢!对不起,我一整天都在编写代码,我的大脑已经不能工作了,谢谢!对不起,我整天都在编代码,我的大脑已经不能工作了