gpt4 book ai didi

java - 代码检查不让我通过

转载 作者:行者123 更新时间:2023-12-02 11:18:18 24 4
gpt4 key购买 nike

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

错误:

/tmp/codecheck.rA4OvRYwJM/InterfaceTester.java:6: error: constructor Sphere in class Sphere cannot be applied to given types;

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

reason: actual and formal argument lists differ in length

/tmp/codecheck.rA4OvRYwJM/InterfaceTester.java:10: error: constructor

Sphere in class Sphere cannot be applied to given types;

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

reason: actual and formal argument lists differ in length 2 errors

这是我的代码和 codecheck 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;
}
}

最佳答案

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

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

关于java - 代码检查不让我通过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50113426/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com