Q:

How to use variable from another class for scanner input?

The problem I have encountered is as follows:
I want to create 10 row outputs representing docking spaces for ships.
Each row contains the ship name and size, which are inputs provided by the applicaiton user. These inputs are retreived using the Scanner class, and should be stored in an array (shipName,ShipSize in each array element).
I would then like to print the rows, as seen in the printArray method below.
I have encountered issues when using the Scanner. When I print the array I get null. I'm unsure if i'm passing the variable from the ship class correctly and if it's saving in the array.
Can you help?
Here is the code:
 import java.util.*;

public class Main {

    static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {

        System.out.println("Choose an option: 1-3");
        System.out.println("1. Dock");
        System.out.println("2. Undock");
        System.out.println("3. Status");

        Scanner scan = new Scanner(System.in);
        int menu = scan.nextInt();

        switch (menu) {
            case 1:
                System.out.println("1. Dock");

                dock();
                break;
            case 2:
                System.out.println("2. Undock");
                break;
            case 3:
                System.out.println("3. Status");
                break;
            default:
                System.out.println("No such option");
                break;
        }

    }

    public static void dock(){
        String[] dock1 = new String[10];

        Ship ship = new Ship();

            System.out.println("Enter ship's name: ");
            ship.setShipName(scan.nextLine());

            System.out.println("Enter ship's size: ");
            ship.setShipSize(scan.nextLine());

            printArray(dock1);

    }

    public static void printArray(String dock1[]){

        for (int i = 0; i<dock1.length ; i++) {
            System.out.print(dock1[i] + " ");
        }
    }

}

Ship class
public class Ship {

public  String shipName;
public  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() {

}}

A:

First you need a refactored ship class:
public class Ship {

private String shipName;
private String shipSize;

public Ship(String shipName, String shipSize) {
    this.shipName = shipName;
    this.shipSize = shipSize;
}

public String getShipName() {
    return shipName;
}

public String getShipSize() {
    return shipSize;
}

public void setShipName(String shipName) {
    this.shipName = shipName;
}

public void setShipSize(String shipSize) {
    this.shipSize = shipSize;
}

}
Then you can begin fixing your errors in the Main.java:

You are always creating a new array. The ships will be stored, but with the next call they all gone.
You use a String array. Because you are creating objects of your own class, you should store them in a array of the ship class.
You don't get a dock number or you are checking if there is still space in the dock.
You have only once the chance to do a operation once

So there is a solution:
import java.util.*;

public class Main {

    static Scanner scan = new Scanner(System.in);
    //Create a global array
    private static Ship[] dock1 = new Ship[10];

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        //Repeat until the program gets closed
        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");
            System.out.println("4. Exit");

            int menu = scan.nextInt();

            switch (menu) {
                case 1:
                    System.out.println("1. Dock");
                    dock();
                    break;
                case 2:
                    System.out.println("2. Undock");
                    break;
                case 3:
                    System.out.println("3. Status");
                    printArray();
                    break;
                case 4:
                    System.exit(0);
                default:
                    System.out.println("No such option");
                    break;
            }
        }

    }

    public static void dock(){

        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:");

        //Check if the dock number is valid
        int i = Integer.valueOf(scan.nextLine());
        if (i >= 0 && i < 10 && dock1[i] == null){
            //Add ship to the dock
            dock1[i] = new Ship(name, size);
        }
        else{
            System.out.println("Couldn't dock");
        }

    }

    public static void printArray(){

        System.out.println("Docks:");

        for (int i = 0; i < dock1.length ; i++) {

            if (dock1[i] != null){
                System.out.println(i + ".: " + dock1[i].getShipName() + "(" + dock1[i].getShipSize() + ")");
            }
            else {
                System.out.println(i + ".: Empty");
            }

        }
    }

}

