Advertisement
cgorrillaha

Untitled

Jan 11th, 2022
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.09 KB | None | 0 0
  1. Horse[] spaces;
  2. /** Returns the index of the space that contains the horse with the specified name.
  3.  * Precondition: No two horses in the barn have the same name.
  4.  * @param name the name of the horse to find
  5.  * @return the index of the space containing the horse with the specified name;
  6.  * -1 if no horse with the specified name is in the barn.
  7.  */
  8.  public int findHorseSpace(String name){
  9.     int out=-1;
  10.     for(int i=0; i<spaces.length; i++){
  11.         Horse h=spaces[i];
  12.         if(h!=null&&h.getName().equals(name)){
  13.             out=i;
  14.         }
  15.     }
  16.     return out;
  17.  }
  18.  
  19.  public int findHorseSpace(String name){    
  20.     for(int i=0; i<spaces.length; i++){
  21.         if(spaces[i]!=null&&spaces[i].getName().equals(name)){
  22.             return i;
  23.         }
  24.     }
  25.     return -1;
  26.  }
  27.  
  28.  public int findHorseSpace(String name){    
  29.     for(int i=0; i<spaces.length; i++){
  30.         if(spaces[i]!=null){
  31.             if(spaces[i].getName().equals(name)){
  32.                 return i;
  33.             }
  34.         }
  35.     }
  36.     return -1;
  37.  }
  38.  
  39.  public int findHorseSpace(String name){
  40.     int out=-1;
  41.     while(out<0){
  42.         Horse h=spaces[i];
  43.         if(h!=null&&h.getName().equals(name)){
  44.             out=i;
  45.         }
  46.     }
  47.     return out;
  48.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement