当前位置: 首页 > 知识库问答 >
问题:

我对编码是新手,试图修复这些错误,但不知道如何做到这一点[重复]

赵昊阳
2023-03-14

任务是求圆的面积和周长以及球体的面积和体积。我不知道如何修复错误,我已经尝试过了。

代码:

    import java.util.Scanner;
    public class RoundThingsDriver
    {
      public static void main(String[] args) 
      {
        double area, circumference, volume, surfaceArea, radius;
        Scanner scan = new Scanner(System.in);
 
        System.out.println("Enter a radius: ");
        radius = scan.nextDouble();

        area = roundThings.calcAreaCircle(radius);
        outPut("circle", "circumference", radius, area);

       circumference = roundThings.calcCircumCircle(radius);
       outPut("sphere", "surface area", radius, surfaceArea);

       volume = roundThings.calcVolumeSphere(radius);
       outPut("sphere", "volume", radius, volume);

       scan.close();
     }
      public static void outPut(String shapeName, String typeValue, double radiusInputted, double 
     actualValue);
     {
       System.out.println("The"+typeValue+"of a"+shapeName+"with a radius 
       of"+radiusInputted+"is"+actualValue);
      }
    }
     public class roundThings
   {
        public static double calcAreaCircle(double radius)
     {

       double area = radius * radius * Math.PI;

       return area; 

     }
     public static double calcCircumCircle(double radius)
     {
       double circumference = 2 * Math.PI * radius;

       return circumference;
     }
     public static double calcAreaSphere(double radius)
     {
       double surfaceArea = 4 * Math.PI * radius * radius;

       return surfaceArea;
     }
     public static double calcVolumeSphere(double radius)
     {
       double Volume = (4/3) * Math.PI * (radius*radius*radius);

       return Volume;
     }
   }

错误:

 javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . Main.java roundThings.java
Main.java:4: error: class RoundThingsDriver is public, should be declared in a file named RoundThingsDriver.java
public class RoundThingsDriver
       ^
Main.java:25: error: missing method body, or declare abstract
  public static void outPut(String shapeName, String typeValue, double radiusInputted, double actualValue);
                     ^
Main.java:27: error: cannot find symbol
    System.out.println("The"+typeValue+"of a"+shapeName+"with a radius of"+radiusInputted+"is"+actualValue);
                             ^
  symbol:   variable typeValue
  location: class RoundThingsDriver
Main.java:27: error: cannot find symbol
    System.out.println("The"+typeValue+"of a"+shapeName+"with a radius of"+radiusInputted+"is"+actualValue);
                                              ^
  symbol:   variable shapeName
  location: class RoundThingsDriver
Main.java:27: error: cannot find symbol
    System.out.println("The"+typeValue+"of a"+shapeName+"with a radius of"+radiusInputted+"is"+actualValue);
                                                                           ^
  symbol:   variable radiusInputted
  location: class RoundThingsDriver
Main.java:27: error: cannot find symbol
    System.out.println("The"+typeValue+"of a"+shapeName+"with a radius of"+radiusInputted+"is"+actualValue);
                                                                                               ^
  symbol:   variable actualValue
  location: class RoundThingsDriver
6 errors
compiler exit status 1

共有1个答案

鲁鸿
2023-03-14

>

  • 为了进行编译,需要将代码放入名为RoundThingsDriver的文件中。java。这就是错误消息告诉您要做的。类RoundThingsDriver是公共的,应在名为RoundThingsDriver的文件中声明。Java语言

    在输出方法的头的末尾,有一个分号。这里不应该用这个。开始的花括号需要立即跟随方法标题。中间唯一允许的是空白。

  •  类似资料: