简体   繁体   English

程序在NetBeans中运行,但没有命令提示符

[英]Program running in NetBeans but not command prompt

I am trying to design and implement a Java class to represent a 3-D geometric shape. 我正在尝试设计和实现一个Java类来表示3D几何形状。 The class should contain a constructor, appropriate data fields and methods to return the volume of the shape, and the surface area of the shape and any other methods that seem to make sense for your shape. 该类应包含一个构造函数,适当的数据字段和方法以返回形状的体积,形状的表面积以及其他对您的形状有意义的方法。

However, I got everything to work fine in Net Beans, but when I try to run it in the command prompt I receive: 但是,我在Net Beans中一切正常,但是当我尝试在命令提示符下运行它时,我收到:

error package Cube doesn't exist

error cannot find symbol

both of these error are referring to the class cube 这两个错误都指向类多维数据集

My code is as follows. 我的代码如下。

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

Simple - when you save it into a .java file, remove the line "package cube;" 简单-将其保存到.java文件时,删除“ package cube”行; and save. 并保存。 It should now work - "package" is used for your IDE, not with notepad/cmd prompt. 现在应该可以使用-“包”用于IDE,而不用于notepad / cmd提示符。 Save your file as RandyGilmanHW4.java 将文件另存为RandyGilmanHW4.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM