Java 我需要帮助重载构造函数和创建接受类作为参数的构造函数
我的代码取自我以前的实验室,在那里我们计算了用户输入的两个坐标之间的距离。如何创建接受坐标作为参数的重载构造函数Java 我需要帮助重载构造函数和创建接受类作为参数的构造函数,java,class,constructor,class-constructors,Java,Class,Constructor,Class Constructors,我的代码取自我以前的实验室,在那里我们计算了用户输入的两个坐标之间的距离。如何创建接受坐标作为参数的重载构造函数 public class airport { private static double PI = 3.14159; private static double earthRadius = 10800 / PI; private static double distance; private static double deltaChange;
public class airport {
private static double PI = 3.14159;
private static double earthRadius = 10800 / PI;
private static double distance;
private static double deltaChange;
// Main method
public static void main(String[] args) {
coordinates pointA = new coordinates(Lat1, Long1);
coordinates pointB = new coordinates(Lat2, Long2);
Scanner stdin = new Scanner(System.in);
// Coordinates prompted/entered
System.out.print("Enter your coordinates: \n");
System.out.print("Lat 1: ");
double Lat1 = stdin.nextDouble();
System.out.print("Long 1: ");
double Long1 = stdin.nextDouble();
// Coordinates(2) prompted/entered
System.out.print("Lat 2: ");
double Lat2 = stdin.nextDouble();
System.out.print("Long 2: ");
double Long2 = stdin.nextDouble();
}
public airport(double a, double b) {
this.Lat1 = a;
this.Long1 = b;
}
public airport(double a, double b) {
}
public airport() {
}
}
}
哦,“导入myPackage.myclass”不起作用。好吧,提醒一下,每次编辑后我都没有“保存”我的坐标文件,所以现在我的坐标对象PointA和PointB起作用了。lol在那里学到的一课。但仍然需要帮助。代码无法编译。请阅读。欢迎来到SO!你应该在问题本身中编辑任何额外的信息(你的评论)。我建议你不要在这里复制粘贴你的全部作业。把具体的问题用你自己的话来说,否则人们可能会认为你想要家庭作业的答案(这在这里是不受欢迎的),然后转身离开。问题应该是关于具体问题的,每个问题可能有一个问题,除非它们是上下文相关的(这并不意味着来自同一个作业)。查看和。
public class coordinates {
coordinates(double x, double y)
{
this.latitude = x;
this.longitude = y;
}
private double latitude = 0;
private double longitude = 0;
//mutator
public void setLat(double lat)
{
this.latitude = lat;
}
public void setLong(double lon)
{
this.longitude = lon;
}
public double getLat()
{
return latitude;
}
public double getLong()
{
return longitude;
}
}