so my assignment is to create an object named city and have the longitude, latitude and name of the city and then ask for the number of cities, then the users input of the name, longitude, and latitude into an array for access. How would i accomplish this with what i have now?
import java.util.Scanner;
public class Assignment3 {
public static void main(String[] args) {
Scanner lat = new Scanner(System.in); //for double data
Scanner lon = new Scanner(System.in); //for double data
Scanner city = new Scanner(System.in); //for string data
Scanner in = new Scanner(System.in); //for int
System.out.print("How many cities? ");
int number = in.nextInt();
City [] cities = new City [number];
for(int i = 1; i <= number; i++){
System.out.println("City # " + i);
System.out.print("Enter name: " );
String name = city.Next();
System.out.print("Enter longitude: ");
double longitude = lon.nextDouble();
System.out.println("Enter latitude: ");
double latitude = lat.nextDouble();
}
}
}
public class City {
String name; //name of cities
double lon, lat; //longitude & latitude
City(String name, double lon, double lat)
{
this.name = name;
this.lon = lon;
this.lat = lat;
}
public void report(){ //should report current position of a city
System.out.println("City: " + this.name); // displays city name
System.out.println("Longitude: " + this.lon); //displays longitude
System.out.println("Latitude: " + this.lat); //displays latitude
}
public double distanceFrom(City otherCity){ //should calculate the distance
return 0;
}
}
The point is so that you can then ask for the cities direct location and then the distance between them. Any help is greatly appreciated thank you