import java.util.ArrayList;

public class Account
{
    // package access for testing
    String username;

    // added for testing
    static ArrayList<String> notAvailable;

    public Account(String requestedName)
    {
        if(isAvailable(requestedName))
        {
            username = requestedName;
        }
        else
        {
            int n = 1;

            while( ! isAvailable(requestedName + n) )
                n++;

            username = requestedName + n;
        }
    }

    // implemented for testing
    public static boolean isAvailable(String str)
    {
        return ! notAvailable.contains(str);
    }

    public String getShortenedName()
    {
        String shortened = username;

        int i = 1;
        while(i < shortened.length())
        {
            if(shortened.substring(i, i + 1).equals("-"))
            {
                shortened = shortened.substring(0, i - 1) +
                        shortened.substring(i + 1);

                i--;
            }
            else
            {
                i++;
            }
        }

        return shortened;
    }
}
