0
我試圖設計和實現一個Java類來表示三維幾何形狀。該類應該包含一個構造函數,適當的數據字段和返回形狀體積的方法,以及形狀的表面區域以及其他任何似乎對您的形狀有意義的方法。程序在NetBeans中運行但不是命令提示符
不過,我把一切都在淨豆做工精細,但當我嘗試在命令提示符下運行它,我得到:
error package Cube doesn't exist
error cannot find symbol
這兩個錯誤指的是類立方
我的代碼如下。
package cube;
public class Cube {
private double side = 0.0;
public Cube(){//begin constructor
side = 1.0;
}//end constructor
public void setSide (double length) {//begin method
side = length;
}//end method
public double getSide() {//begin method
return side;
}//end method
public double calculateVolume() {
double volume2 = side * side * side;
return volume2;
} // end method
public double calculateSurfaceArea() {
double area = 6 * (side * side);
return area;
} // end method
}//end class
package randygilmanhw4;
import java.util.Scanner;
import cube.Cube;//imports class Cube
public class RandyGilmanHW4 {
public static void main(String[]args) {//begin main
//Display welcome message
System.out.println("Hello Welcome to Randy's Cube");
System.out.println(" Calculator Program");
System.out.println("");
Cube one = new Cube();
//declare variables within main
double area;
double volume2;
double side1;
Scanner input = new Scanner(System.in);
System.out.println("Please enter a length of the side of the cube in cm: ");
side1 = input.nextDouble();
one.setSide(side1);
volume2 = one.calculateVolume();
System.out.printf("Cube's volume is: %4.2f cm^3", volume2);// OUTPUT
System.out.println("\n");
one.setSide(side1);
area = one.calculateSurfaceArea();
System.out.printf("Cube's surface area is: %4.2f cm^2 ", area);// OUTPUT
} // end main
}//end class
你的軟件包是'c'不是'C'ube,即以小寫'c'開頭! – A4L
如果問題不是A4L指出的問題,請在命令行中共享您正在運行的「java」命令。 –
當我嘗試在命令提示符下編譯java命令時,「共享」java命令是什麼意思,我輸入javac RandyGilmanHW4.java,那麼它給我所有這些錯誤? –