Java 在我的学校项目中使用四参数构造函数

Java 在我的学校项目中使用四参数构造函数,java,Java,所以,我正在为学校做这个项目,我不知道如何实施测试课程,把所有这些放在一起。我完成了大部分工作,但不知道如何使用位置B和位置A进行地理定位 下面是该项目的任务 您的任务是创建一个程序,该程序可以使用一些方便的抽象(类)和一些数学知识计算到地理位置的距离 我将发布整个项目的所有代码。注释是每个部分的说明。我只需要最后一节课的帮助,这部分的说明如下 **c。使用四参数构造函数,创建一个表示学校的Place对象。使用toString方法确保它工作正常。 ** 在代码中,我在它下面留下了我的空间,以显示

所以,我正在为学校做这个项目,我不知道如何实施测试课程,把所有这些放在一起。我完成了大部分工作,但不知道如何使用位置B和位置A进行地理定位

下面是该项目的任务

您的任务是创建一个程序,该程序可以使用一些方便的抽象(类)和一些数学知识计算到地理位置的距离

我将发布整个项目的所有代码。注释是每个部分的说明。我只需要最后一节课的帮助,这部分的说明如下 **c。使用四参数构造函数,创建一个表示学校的Place对象。使用toString方法确保它工作正常。 **

在代码中,我在它下面留下了我的空间,以显示它将去哪里在我的主课上

这是我为每个类编写的代码

GeoLocation.Java

Main.java我需要帮助的部分在这里

package com.GeoLocation;
import com.GeoLocation.GeoLocation;
import com.GeoLocation.Place;

public class Main {
//Create a GeoLocation object that stores the geographic location of the Frisco ISD administration building.  Print a call to GeoLocation's toString method to ensure it worked.
    public static void main(String[] args) {
        GeoLocation Location = new GeoLocation();
        Location.Latitude = 33.123961;
        Location.Longitude = -96.798735;
//Using the three-parameter constructor, make a Place object that represents the Frisco ISD administration building.  Print a call to Place's toString method to ensure it worked.
        String addressA = Location.toString();
        System.out.println(addressA);
        Place PlaceA = new Place("FISD", "Address", Location);
        String AddressB = PlaceA.toString();
        System.out.println(AddressB);
//Using the four-parameter constructor, make a Place object that represents your school.  Use the toString method to ensure it worked.



//        d. Use Place's distanceTo method to output the distance between them.
//
//            ▪ Check with a neighbor to make sure you got the same distance.
//            ▪ Accuse your neighbor of faulty code if their result does not match your result.
//            ▪ Consult Google Maps to determine who was right (note that driving directions will be distance along roads, not straight-line distances; Google Maps can do both).
//                • Rejoice / weep (as applicable).
        double GeoLocDistance;
        GeoLocDistance = PlaceA.distanceTo(PlaceB);
        System.out.println(GeoLocDistance);

    }
}


您已经完成了三参数构造函数任务,是吗?因此,希望四参数构造函数部分应该很好:您只需要给构造函数lat和long值,而不是给它一个预组装的地理位置对象。我猜当它说“toString”时,意味着在Geolocation对象上,四参数构造函数为您组装,因为您没有toString。(除非,也就是说,你被要求写一篇?@Rup我的老师给了我们,我很困惑。我需要帮助你的意思是
placemyschool=newplace(“我的学校名称”,“123 Station St”,40.7128,-74.0060)
?正如Rup所说,你在这里使用了一个三参数构造函数:
placeplace PlaceA=newplace(“FISD”,“Address”,Location)。也就是说,传递三个不同的参数来创建一个新的
位置
。c部分只是要求您使用四参数构造函数(如Bohemian的示例)。请输入姓名、地址、纬度和经度。
package com.GeoLocation;

public class Place {

//    2. Make a new class called Place.  Place is an abstraction of a particular place, for example a business or a school.  A Place has a GeoLocation along with some more information about that place.  We say that the Place class is a client of the GeoLocation class (it uses its objects).
//        a. Instance variables
//            ▪ String      name     – a place's name, e.g. "McDonald's"
//            ▪ String      address  – the full address (street, city, etc.) of a particular place
//            ▪ GeoLocation location – the place's geographic location details
    String Name;
    String Address;
    double Latitude, Longitude;

    GeoLocation location = new GeoLocation();
//            ▪ public Place(String n, String a, double lati, double longi) – constructor, initializes all instance variables to the given values
//    • This constructor passes in the values for YOU to initialize the location object. Use these values to instantiate the object.
    public Place(String n, String a, double Lati, double Longi)
    {
        Name = n;
        Address = a;
        Latitude = Lati;
        Longitude = Longi;
        location.Latitude= Lati;
        location.Longitude = Longi;
    }
//            ▪ public double distanceTo(Place other) – returns the distance between two places.  There should only be one line inside this method:
//return location.distanceTo(other.location);
    public double distanceTo(Place other){
        return location.distanceTo(other.location);
    }
//            ▪ public Place(String n, String a, GeoLocation loc) – alternate constructor, initializes all instance variables to the given values
//                • This constructor requires an already constructed GeoLocation object.  Just like with primitive types, the constructor will use the supplied values to initialize this object's instance variables.
    public Place(String n, String a, GeoLocation loc)
    {
        Name = n;
        Address = a;
        location = loc;

    }
}

package com.GeoLocation;
import com.GeoLocation.GeoLocation;
import com.GeoLocation.Place;

public class Main {
//Create a GeoLocation object that stores the geographic location of the Frisco ISD administration building.  Print a call to GeoLocation's toString method to ensure it worked.
    public static void main(String[] args) {
        GeoLocation Location = new GeoLocation();
        Location.Latitude = 33.123961;
        Location.Longitude = -96.798735;
//Using the three-parameter constructor, make a Place object that represents the Frisco ISD administration building.  Print a call to Place's toString method to ensure it worked.
        String addressA = Location.toString();
        System.out.println(addressA);
        Place PlaceA = new Place("FISD", "Address", Location);
        String AddressB = PlaceA.toString();
        System.out.println(AddressB);
//Using the four-parameter constructor, make a Place object that represents your school.  Use the toString method to ensure it worked.



//        d. Use Place's distanceTo method to output the distance between them.
//
//            ▪ Check with a neighbor to make sure you got the same distance.
//            ▪ Accuse your neighbor of faulty code if their result does not match your result.
//            ▪ Consult Google Maps to determine who was right (note that driving directions will be distance along roads, not straight-line distances; Google Maps can do both).
//                • Rejoice / weep (as applicable).
        double GeoLocDistance;
        GeoLocDistance = PlaceA.distanceTo(PlaceB);
        System.out.println(GeoLocDistance);

    }
}