added constructor, validateAddress, setCoordsForAddress, and setDestinationAddress

This commit is contained in:
Fennel Kora 2024-04-12 22:30:29 -04:00
parent 35438c703a
commit 3ad2b6aae4

View file

@ -1,16 +1,32 @@
public class Destination {
private String address;
private class coordinates {
private float longitude;
private float latitude;
private String destinationAddress;
private double[] coordinates; //stores lat/long as terms in the array
private float getLongitude() {return longitude;}
private float getLatitude() {return latitude;}
public void setLongitude(float coord) {longitude = coord;}
public void setLatitude(float coord) {latitude = coord;}
public float[] getCoordinates() {
float[] coordsArray = {getLatitude(), getLongitude()};
return coordsArray;
public Destination(String inputAddress) { //constructor takes address, validates, then retrieves GPS coordinates and stores them
setDestinationAddress(inputAddress);
}
private boolean validateAddress() { //determines if provided address is valid
//execute call to address verification service API
//for the purposes of control flow in this example, will always return true
return true;
}
private void setCoordsForAddress() {
//execute call using address out to covnersion API such as Google Geocoding code example
//tmpCoords = geocodingAPI(address); with the assumption an array of coordinates is returned
//these explicit declarations will serve as testing values
double[] tmpCoords = { 27.993718340483223, -80.63008635738797};
coordinates[0] = tmpCoords[0];
coordinates[1] = tmpCoords[1];
}
public void setDestinationAddress(String newAddress) {
if (validateAddress()) {
destinationAddress = newAddress;
setCoordsForAddress();
} else {
//prompt error message
}
}
}