编译问题
初学java,总是编译不过去,请帮帮忙
Point.java文件,存于E:\java\Geometry
package Geometry;
public class Point{
//Create a point from coordinates
public Point(double xVal,double yVal){
x=xVal;
y=yVal;
}
//Create a point form another Point object
public Point(final Point oldPoint){
x=oldPoint.x;
y=oldPoint.y;
}
//move a point
public void move(double xDelta,double yDelta){
x+=xDelta;
y+=yDelta;
}
//Calculate the distance to another point
public double distance(final Point aPoint){
return Math.sqrt((x-aPoint.x)*(x-aPoint.x)+(y-aPoint.y)*(y-aPoint.y));
}
//Convert a point to a string
public String toString(){
return Double.toString(x)+", "+y;
}
//Coordinates of the point
private double x;
private double y;
}
Line.java文件,存于E:\java\Geometry
package Geometry;
public class Line{
//Create a line from two points
public Line(final Point start,final Point end){
this.start=new Point(start);
this.end=new Point(end);
}
//Create a line from two coordinate pairs
public Line(double xStart,double yStart,double xEnd,double yEnd){
start=new Point(xStart,yStart); //Create the start point
end=new Point(xEnd,yEnd); //Create the end point
}
//Calculate the length of a line
public double length(){
return start.distance(end); //Use the method from the Point class
}
//Convert a line to a string
public String toString(){
return "(" + start + "):(" + end + ")"; //As "(start):(end)"
}
Point start; //Start point of line
Point end; //End point of line
}
TryGeometry.java文件,调用上面的Point和Line类,存于E:\java\Geometry
import Geometry.*;
public class TryGeometry{
public static void main(String[] args){
//Create two points and display them
Point start=new Point(0.0,1.0);
Point end=new Point(5.0,6.0);
System.out.println("Points created are "+start+"and"+end);
//Create two lines and display them
line line1=new Line(start,end);
line line2=new Line(0.0,3.0,3.0,0.0);
System.out.println("Lines created are "+linel+" and "+line2);
}
}
类Point和Line都编译通过了,但TryGeometry就是编译不过
E:\java\Geometry>javac -classpath ".;e:\java" TryGeometry.java
TryGeometry.java:6: cannot access Point
bad class file: .\Point.class
class file contains wrong class: Geometry.Point
Please remove or make sure it appears in the correct subdirectory of the classpa
th.
Point start=new Point(0.0,1.0);
^
1 error