Hey all I'm very new to Java and I'm having trouble with arrays. I can do basic arrays where I can display an index against a value. I have this particular program that displays distances between cities. I have got it work using nested if blocks but I want to get it to work using arrays. I'm not sure even where to start and the crappy Deitel&Deitel book I'm sure a lot of you are aware of is no help.
Heres the original table I had to work with:

This is how I got it to work using nested if blocks.
import java.util.Scanner;
public class Destination
{
private int destinationLocation;
private int origin;
public Destination()
{}
public void setDestinationLocation(int destLo)
{
destinationLocation = destLo;
}
public int getDestinationLocation()
{
return destinationLocation;
}
public void setOrigin(int ogn)
{
origin = ogn;
}
public int getOrigin()
{
return origin;
}
public void determineDistance()
{
Scanner input = new Scanner( System.in );
System.out.print("Please select the origin of your trip: \n1. Belfast \n2. Cork \n3. Dublin \n4. Galway \n5. Limerick\n");
origin=input.nextInt();
System.out.print("Please select the destination of your trip: \n1. Belfast \n2. Cork \n3. Dublin \n4. Galway \n5. Limerick\n");
destinationLocation=input.nextInt();
if ( origin == 1 )
{
if ( destinationLocation == 2)
System.out.println( "The distance between Belfast and Cork is 300 Kilometers");
if ( destinationLocation == 3)
System.out.println( "The distance between Belfast and Dublin is 150 Kilometers");
if ( destinationLocation == 4)
System.out.println( "The distance between Belfast and Galway is 200 Kilometers");
if ( destinationLocation == 5)
System.out.println( "The distance between Belfast and Limerick is 300 Kilometers");
}
else if (origin == 2)
{
if ( destinationLocation == 1)
System.out.println( "The distance between Cork and Belfast is 300 Kilometers");
if ( destinationLocation == 3)
System.out.println( "The distance between Cork and Dublin is 256 Kilometers");
if ( destinationLocation == 4)
System.out.println( "The distance between Cork and Galway is 150 Kilometers");
if ( destinationLocation == 5)
System.out.println( "The distance between Cork and Limerick is 75 Kilometers");
}
else if (origin == 3)
{
if ( destinationLocation == 1)
System.out.println( "The distance between Dublin and Belfast is 150 Kilometers");
if ( destinationLocation == 2)
System.out.println( "The distance between Dublin and Cork is 256 Kilometers");
if ( destinationLocation == 4)
System.out.println( "The distance between Dublin and Galway is 180 Kilometers");
if ( destinationLocation == 5)
System.out.println( "The distance between Dublin and Limerick is 220 Kilometers");
}
else if (origin == 4)
{
if ( destinationLocation == 1)
System.out.println( "The distance between Galway and Belfast is 200 Kilometers");
if ( destinationLocation == 2)
System.out.println( "The distance between Galway and Cork is 150 Kilometers");
if ( destinationLocation == 3)
System.out.println( "The distance between Galway and Dublin is 180 Kilometers");
if ( destinationLocation == 5)
System.out.println( "The distance between Galway and Limerick is 134 Kilometers");
}
else if (origin == 5)
{
if ( destinationLocation == 1)
System.out.println( "The distance between Limerick and Belfast is 300 Kilometers");
if ( destinationLocation == 2)
System.out.println( "The distance between Limerick and Cork is 75 Kilometers");
if ( destinationLocation == 3)
System.out.println( "The distance between Limerick and Dublin is 220 Kilometers");
if ( destinationLocation == 4)
System.out.println( "The distance between Limerick and Galway is 134 Kilometers");
}
else
System.out.println( "Valid numbers not entered please try again" );
}
}
public class DestinationTest
{
public static void main( String args[] )
{
Destination myDestination = new Destination();
myDestination.determineDistance();
}
}
Any pointers would be greatly appreciated