well basically i have this code working to display distance to nearest station and the station name but i want it to show what line the station nearest is located on i've tried to figure it out but just dont seem to be getting anywhere with it the code (including what I tried to do to get it to work) is below
any help would be much appreciated
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package calculatedistance;
import javax.swing.*;
/**
*
* @author Jade
*/
public class CalculateDistance {
private static int i;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double tempBearing;
double tempLength;
double distanceToClosest;
// array of stations
Station[]stations = new Station[16];
//populate array list
stations[0] = new Station("Trim Bridge", new Location(65.0,2600.0));
stations[1] = new Station("Windmill Hill", new Location(65.0,4800.0));
stations[2] = new Station("Pirac Cresent", new Location(82.0,3400.0));
stations[3] = new Station("Easton", new Location(84.0,4800.0));
stations[4] = new Station("Parkway", new Location(105.0,3400.0));
stations[5] = new Station("Temple Fields", new Location(149.0,3000.0));
stations[6] = new Station("St Judes Hill", new Location(344.0,1800.0));
stations[7] = new Station("Clifton Street", new Location(287.0,4400.0));
stations[8] = new Station("Tivoli", new Location(277.0,2200.0));
stations[9] = new Station("Jacobs Well", new Location(251.0,1200.0));
stations[10] = new Station("Central", new Location(240.0,2000.0));
stations[11] = new Station("Newbridge", new Location(244.0,4400.0));
stations[12] = new Station("Weston-On-Shore", new Location(235.0,5800.0));
stations[13] = new Station("Shakespeare Court", new Location(183.0,2000.0));
stations[14] = new Station("St Dennis", new Location(180.0,400.0));
stations[15] = new Station("Maxbridge", new Location(180.0,800.0));
//array of station lines
Line[]lines = new Line[4];
//populate array list
lines[0] = new Line("Docks Line");
lines[1]= new Line("Brunel Line");
lines[2]= new Line("Gyratory Line");
lines[3]= new Line("Interchange");
//get current location
String temp = JOptionPane.showInputDialog("Bearing to current location");
tempBearing = Double.parseDouble(temp);
temp= JOptionPane.showInputDialog("Distance from origin of current location");
tempLength = Double.parseDouble(temp);
Location current = new Location(tempBearing, tempLength);
Station closest = stations[0];
distanceToClosest = current.calcDistance(stations[0].location);
for(int i=1; i <stations.length; i++){
double tempDist = current.calcDistance(stations[i].location);
if (tempDist<distanceToClosest){
closest = stations[i];
distanceToClosest=tempDist;
}// if (tempDist<distanceToClosest)
}//for loop
if (closest.name= "Weston-On-Shore" or "Newbridge" or "Central" or "St Dennis" or "Winmill Hill");
Lines = "Docks Line";
else if (closest.name = "Clifton Street" or "Tivoli" or"Easton");
Lines = "Brunel Line";
else if (closest.name = "Shakespeare Court" or "Temple Fields" or "Pirac Crescent" or "St Judes Hill")
Lines = "Gyratory Line";
JOptionPane.showMessageDialog(null, "the closest station is "+closest.name + "\nIt is " +distanceToClosest + " m away on a bearing of");
}
}
class Station{
Location location;
String name;
public Station (String n, Location l){
name = n;
location = l;
}
}//class station
class Location{
double bearing;
double length;
public Location(){
bearing = 0.0;
length = 0.0;
}
public Location (double b, double l){
bearing = b;
length = l;
}
public double calcDistance(Location l){
double angle = Math.abs(bearing - l.bearing); // calculate angle between bearings
double temp = (length*length)+(l.length*l.length)-(2*length*l.length*Math.cos(Math.toRadians(angle)));
return Math.pow(temp, 0.5);
}
}//location