首页 > 解决方案 > Codecheck 不让我通过

问题描述

嘿,我有一个发出错误的代码。不知道为什么以及如何。但是任何人都可以帮我解决这个问题吗?

错误:

/tmp/codecheck.rA4OvRYwJM/InterfaceTester.java:6:错误:Sphere 类中的构造函数 Sphere 不能应用于给定类型;

   GeometricSolid shape = new Sphere(10);
                          ^   required: no arguments   found: int  

原因:实际参数列表和形式参数列表的长度不同

/tmp/codecheck.rA4OvRYwJM/InterfaceTester.java:10:错误:构造函数

Sphere 类中的 Sphere 不能应用于给定类型;

   shape = new Sphere(1);
           ^   required: no arguments   found: int 

原因:实际参数列表和形式参数列表长度不同 2 错误

这是我的代码和代码检查的链接http://www.codecheck.it/files/18040616263h5pl4lvxfmzj6u9w7xty4dfu

 /**
 * Write a description of class asdasdasd here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
public interface GeometricSolid
{
    public double volume();

}

import java.util.*;
public class Sphere implements GeometricSolid
{
double radius;
    /**
     * Gets the volume of sphere
     * @return volume volume of sphere
     */
    public double volume()
    {
        double volume = 4.0 * Math.PI * Math.pow(this.radius, 3) / 3.0;
        return volume;
    }

    /**
     * Get radius of sphere
     * @return the radius of sphere
     */
    public double getRadius()
    {
        return radius;
    }
    /**
     * set radius for sphere
     * @param newRadius of a sphere
     */
    public void setRadius(int newRadius)
    {
        radius = newRadius;
    }
}

标签: java

解决方案


Sphere您必须向以半径作为参数并将其传递给变量的类添加一个构造函数。
例如:

public Sphere(double radius){
     this.radius = radius;
}

推荐阅读