JAVA初学者遇到困难求救~!!!
程序包括两个源文件。这是第一个:publicclassSphere{staticfinaldoublePI=3.14;staticintcount=0;//Instanc...
程序包括两个源文件。
这是第一个:
public class Sphere{
static final double PI=3.14;
static int count=0;
//Instance variables
double radius;
double xCenter;
double yCenter;
double zCenter;
//First Class constructor
Sphere(double theRadius,double x,double y,double z){
radius=theRadius; //Set the radius
//Set the coordinates of the center
xCenter=x;
yCenter=y;
zCenter=z;
++count; //Update objiect count
}
//Construct a unit sphere at a point
Sphere(double x,double y,double z){
xCenter=x;
yCenter=y;
zCenter=z;
radius=1.0;
++count;
}
//Construct a unit sphere at the origin
Sphere(){
xCenter=0.0;
yCenter=0.0;
zCenter=0.0;
radius=1.0;
++count;
}
//Static method to report the number of objects created
static int getCount(){
return count; //Return current object count
}
//Instance method to calculate volume
double volume(){
return 4.0/3.0*PI*radius*radius*radius;
}
}
这是第二个:
class CreateSpheres{
public static void main(String[] args){
System.out.println("Number of objects ="+ Sphere.getCount());
Sphere ball=new Sphere(4.0,0.0,0.0,0.0); //Create a sphere
System.out.println("Number of objects ="+ ball.getCount());
Sphere globe=new Sphere(12.0,1.0,1.0,1.0); //Create a sphere
System.out.println("Number of objects="+Sphere.getCount());
Sphere eightBall=new Sphere(10.0,10.0,0.0);
Sphere oddBall=new Sphere();
System.out.println("Number of objects=" +Sphere.getCount());
//Output the volume of each sphere
System.out.println("ball volume="+ball.volume());
System.out.println("globe volume="+globe.volume());
System.out.println("eigtBall volume="+eightBall.volume());
System.out.println("oddBal volume="+oddBall.volume());
}
}
两个源文件编译通过,但是运行得到如下提示:
java.lang.NoClassDefFoundError: CreatSpheres
Exception in thread "main"
P.S:两个源文件在同一个目录下。 展开
这是第一个:
public class Sphere{
static final double PI=3.14;
static int count=0;
//Instance variables
double radius;
double xCenter;
double yCenter;
double zCenter;
//First Class constructor
Sphere(double theRadius,double x,double y,double z){
radius=theRadius; //Set the radius
//Set the coordinates of the center
xCenter=x;
yCenter=y;
zCenter=z;
++count; //Update objiect count
}
//Construct a unit sphere at a point
Sphere(double x,double y,double z){
xCenter=x;
yCenter=y;
zCenter=z;
radius=1.0;
++count;
}
//Construct a unit sphere at the origin
Sphere(){
xCenter=0.0;
yCenter=0.0;
zCenter=0.0;
radius=1.0;
++count;
}
//Static method to report the number of objects created
static int getCount(){
return count; //Return current object count
}
//Instance method to calculate volume
double volume(){
return 4.0/3.0*PI*radius*radius*radius;
}
}
这是第二个:
class CreateSpheres{
public static void main(String[] args){
System.out.println("Number of objects ="+ Sphere.getCount());
Sphere ball=new Sphere(4.0,0.0,0.0,0.0); //Create a sphere
System.out.println("Number of objects ="+ ball.getCount());
Sphere globe=new Sphere(12.0,1.0,1.0,1.0); //Create a sphere
System.out.println("Number of objects="+Sphere.getCount());
Sphere eightBall=new Sphere(10.0,10.0,0.0);
Sphere oddBall=new Sphere();
System.out.println("Number of objects=" +Sphere.getCount());
//Output the volume of each sphere
System.out.println("ball volume="+ball.volume());
System.out.println("globe volume="+globe.volume());
System.out.println("eigtBall volume="+eightBall.volume());
System.out.println("oddBal volume="+oddBall.volume());
}
}
两个源文件编译通过,但是运行得到如下提示:
java.lang.NoClassDefFoundError: CreatSpheres
Exception in thread "main"
P.S:两个源文件在同一个目录下。 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询