我需要帮助重载构造函数和创建接受类作为参数的构造函数

时间:2015-10-16 03:40:55

标签: 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;

    // 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() {
    }


    }

}


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;
    }
}

0 个答案:

没有答案