title: No more than a number of the same string name in the same array?
body: <p>The problem I have encountered is as follows: I have created 10 row outputs representing docking spaces for ships.</p>
  
  <p>But the dock can accommodate two sizes of ship; cargo and container. The rows are made up of 5 small and 5 medium. A cargo ship (small) can berth in any available space. A container ship (medium) can berth in the medium space, but not in small spaces.</p>
  
  <p>So if I enter shipName and Container for example it searches the array making sure there is less than 5 Container's so it can dock i.e. save in the array. Can you help?
  Here's my dock method: </p>
  
  <pre><code>import java.util.*;
  
  public class Main {
  
  static Scanner scan = new Scanner(System.in);
  private static Ship[] dock1 = new Ship[10];
  
  public static void main(String[] args) {
  
          Scanner scan = new Scanner(System.in);
  
  
      while(true) {
  
          System.out.println("Choose an option: 1-3");
          System.out.println("1. Dock");
          System.out.println("2. Undock");
          System.out.println("3. Status");
  
          int menu = scan.nextInt();
              switch (menu) {
                  case 1:
                      System.out.println("1. Dock");
                      dock();
                      break;
                  case 2:
                      System.out.println("2. Undock");
                      undock();
                      break;
                  case 3:
                      System.out.println("3. Status");
                      printArray();
                      break;
                  case 4:
                      System.out.println("4. Exit");
                      System.exit(0);
                  default:
                      System.out.println("No such option");
                      break;
              }
          }
  }
  
  public static void dock() {
  
      int dockCapacity = 0;
  
      System.out.println("Enter ship's name: ");
      String name = scan.nextLine();
  
      System.out.println("Enter ship's size: ");
      String size = scan.nextLine();
  
      System.out.println("Enter the ships dock:");
      //search for 5 small 3 med 2 large
  
   //    if what they entered equals shipSize more than 5 than cannot dock.
      for(int i = 1; i &lt; dock1.length; i++) {
          if (dock1[i].getShipSize().equals(size)) {
              System.out.print(dock1[i].getShipSize());
          }
          else {
              System.out.println("Couldn't dock");
          }
      }
      //Check if the dock number is valid
      int i = Integer.valueOf(scan.nextLine());
      if (i &gt;= 0 &amp;&amp; i &lt; 10 &amp;&amp; dock1[i] == null){
          //Add ship to the dock
          dock1[i] = new Ship(name, size);
          System.out.println("Ship has been docked");
      }
      else{
          System.out.println("Couldn't dock");
      }
     // printArray();
  }
  
  public static void undock(){
  
      System.out.println("Status of ships: ");
      printArray();
      System.out.println("Enter ship's name to undock: ");
      String name = scan.nextLine();
      for(int i = 1; i &lt; dock1.length; i++){
      if(dock1[i] != null &amp;&amp; dock1[i].getShipName().equals(name)){
          dock1[i] = null;
          System.out.println("Ship removed");
          break;
      }
      else{
          System.out.println("Ship not docked here");
      }
      }
  
  }
  
  public static void printArray() {
  
      System.out.println("Docks:");
  
      for(int i = 0; i &lt; dock1.length; i++)
      {
          if(dock1[i] == null)
          {
              System.out.println("Dock " + i + " is empty");
          }
          else
          {
              System.out.println("Dock " + i + ": " + dock1[i].getShipName() + " " + dock1[i].getShipSize());
          }
      }
  }
  }
  </code></pre>
  
  <p>Ship class</p>
  
  <pre><code>public class Ship {
  
  private String shipName;
  private  String shipSize;
  
  public String getShipName() {
      return shipName;
  }
  
  public void setShipName(String shipName) {
      this.shipName = shipName;
  }
  
  public String getShipSize() {
      return shipSize;
  }
  
  public void setShipSize(String shipSize) {
      this.shipSize = shipSize;
  }
  
  public Ship(String shipName, String shipSize) {
      this.shipName = shipName;
      this.shipSize = shipSize;
  }
  }
  </code></pre>