A* algorithm sorting the spaces so i can get teh shortest and add to the openlist, closedlist which i have not yet created : ok so im trying to create  a A* algorithm path finder. issue that i have is how do i sort which has teh lowest distance from the bot's space options from the goal. 
 
here is my space class, bot class, goal class, and pathfinder class. its not really ordered but here it is. see if you can lead me in the right direction. this goes all under one src.


    public class Space {
    
    	private int distance;
    	private int x;
    	private int y;
    	public Space(int x, int y){
    		
    		int distancex =Math.abs((x) - Goal.getX());
    		int distancey= Math.abs((y) - Goal.getY());
    		this.x = x;
    		this.y = y;
    		this.distance = (distancex + distancey); 
    	}
    	public int getDistance() {
    		return distance;
    	}
    	public int getX() {
    		return x;
    	}
    	public int getY() {
    		return y;
    	}
    	
    	
    }
this is the pathfinder class.

    import java.util.*;
    public class Pathfinder {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    	
    		
    		Bot Dave = new Bot("Dave");
    		
    		Goal goal = new Goal();
    		
    		System.out.println("Dave's x positon is " + Dave.getX() +"and his y position is "+ Dave.getY());
    		
    		System.out.println("the left space of the bot is " + Dave.checkleft(Dave.getX(), Dave.getY()));
    		System.out.println("the right space of the bot is " + Dave.checkright(Dave.getX(), Dave.getY()));
    		System.out.println("the bottom space of the bot is " + Dave.checkbottom(Dave.getX(), Dave.getY()));
    		System.out.println("the top space of the bot is " + Dave.checkbottom(Dave.getX(), Dave.getY()));
    		
    		
    		Space right = new Space(Dave.getX()+1, Dave.getY());
    		Space left = new Space(Dave.getX()-1, Dave.getY());
    		Space up = new Space(Dave.getX(), Dave.getY()+1);
    		Space down = new Space(Dave.getX(), Dave.getY()-1);
    		
    	
    	
    	}
    	
    	
    
    }

this is the bot class

    import java.util.*;
    
    
    public class Bot {
    	
    	private int x;
    	private int y;
    	private String name;
    
    	public Bot(String Name){
    		this.name = Name;
    		this.x =(int) (Math.random()*100);
    		this.y =(int) (Math.random()*100);			
    	}
    	public String getName() {
    		return name;
    	}
    
    	public int getX() {
    		return x;
    	}
    
    	public int getY() {
    		return y;
    	}
    
    	public int checktop(int x, int y){
    		int distancex =Math.abs((x) - Goal.getX());
    		int distancey= Math.abs((y+1) - Goal.getY());
    		
    		return (distancex + distancey); 
    		
    		
    	}public int checkbottom(int x, int y){
    		int distancex =Math.abs(x - Goal.getX());
    		int distancey= Math.abs((y-1) - Goal.getY());
    		
    		return (distancex + distancey); 
    	}
    	public int checkright(int x, int y){
    	int distancex =Math.abs((x+1) - Goal.getX());
    	int distancey= Math.abs(y - Goal.getY());
    	
    	return (distancex + distancey); 
    		
    	}
    	public int checkleft(int x, int y){
    	int distancex =Math.abs((x-1) - Goal.getX());
    	int distancey= Math.abs(y - Goal.getY());
    	
    	return (distancex + distancey); 
    	
    }
    	
    	}

this is the goal class



    public class Goal {
    private static int x;
    private static int y;
    
    public Goal(){
    	
    	this.x=(int) (Math.random()*100);
    	this.y =(int) (Math.random()*100);
    			
    }
    
    public static int getX() {
    	return x;
    }
    
    public static int getY() {
    	return y;
    }
    
    }