我刚开始接触编程,试图修复这些错误,但不理解如何操作。

huangapple go评论75阅读模式
英文:

I'm new to coding and was trying to fix these errors but did not understand how to do so

问题

代码:

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", "area", radius, area);

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

        surfaceArea = roundThings.calcAreaSphere(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 valueType, double radiusInputted, double actualValue) {
        System.out.println("The " + valueType + " of a " + shapeName + " with a radius of " + radiusInputted + " is " + actualValue);
    }
}

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.0 / 3.0) * Math.PI * (radius * radius * radius);
        return volume;
    }
}

错误信息已修正:

 javac -classpath .:/run_dir/junit-4.12.jar:target/dependency/* -d . RoundThingsDriver.java roundThings.java
英文:

The assignment is to find area and circumference of a circle and area and volume of a sphere. I have no idea how to fix the errors and have tried.

code:

    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;
}
}

ERRORS:

 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

得分: 1

  1. 为了使这段代码编译通过,你需要将代码放入一个名为 RoundThingsDriver.java 的文件中。这就是错误消息告诉你要做的。class RoundThingsDriver 是 public 的,应当声明在名为 RoundThingsDriver.java 的文件中。

  2. outPut 方法的头部末尾,你有一个分号。这里不应该使用分号。左大括号应该紧接着方法头部。唯一允许在两者之间的是空白字符。

英文:
  1. In order for this to compile, you need to put the code in a file called RoundThingsDriver.java. That's what the error message told you to do. class RoundThingsDriver is public, should be declared in a file named RoundThingsDriver.java

  2. At the end of the header of the outPut method, you have a semicolon. That shouldn't be used here. The opening curly brace needs to immediately follow the method header. The only thing allowed in between is whitespace.

huangapple
  • 本文由 发表于 2020年10月1日 09:20:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64147838.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定