Results 1 to 4 of 4
  1. #1
    busdude is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default Need help with 2D array program. Crossing words

    I'm doing a program where the user inputs a list of words and the program arranges them into a 20 X 20 grid of chars, putting in the words that are possible.

    Pasted instructions:
    "
    Write a program that will accept a list of words into an array list of strings, then make a 20 x 20 array of char that contains a crossword puzzle with these words.

    For example, when given the list
    addle, apple, clowning, incline, plan, burr
    your program might display:
    a p p l e
    d
    d
    c l o w n i n g
    e n
    c
    l
    i
    p l a n
    e

    EDIT: the above isn't displaying properly in the forum for some reason, still the idea is clear.


    You may want to use the following method: Place the first word horizontally in the center of the grid. Place the next word vertically. Check if there is a common letter already on the grid, and if all the squares into which you want to place that word are still empty. (If you can't place it on any of the common letters, skip the word.) Then switch back to horizontal, place the next word if possible, and so on.
    "

    code so far:
    Java Code:
    import java.util.ArrayList;
    import java.util.Scanner;
    
    class A2
        {
    
            public A2()
            {
                LIST = new ArrayList<String>();
            }
    
            public void addWord(String word)
            {
                LIST.add(word);
                
            }
            
            public void grid()
            {
                grid = new char[ROWS][COLUMNS];
                
                for (int i = 0; i < ROWS; i ++)
                    for (int j = 0; i < COLUMNS; j++)
                        grid[i][j] = ' ';
                    }
      
        public void insertFirstWord(String LIST)
        {
            
            
            
            
        }
    
       /** 
        public char[][] drawGrid()
        {
          
         
            return 
        }
    */
    private ArrayList<String> LIST;              
           private static final int ROWS = 20;
           private static final int COLUMNS = 20;
           private char[][] grid;       
    
    }      
           
    
    public class A2Tester
        {
            public static void main(String[] args)
            {
                
                 Scanner in = new Scanner(System.in);
                 System.out.println("Enter a list of words to be arranged in a crossword. Enter stop to end the list");
                
                 A2 crossword = new A2();
                 
                      boolean done = false;
            while(!done)
                {
                    String thing = in.nextLine();          
                    crossword.addWord(thing);
        
                    if (thing.equalsIgnoreCase("Stop"))
                    {done = true;}       
            }
            
        }
    }

    I don't know how to start to put the first word in the array list into the grid. you have to seperate the string into chars. Also I'm not sure how to display the 2D array.

    Anything I'm doing wrong so far?
    Last edited by busdude; 11-17-2008 at 02:47 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    New To Java - Need help with 2d arrays program. crossing words program.

    To the original poster, cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.

  3. #3
    busdude is offline Member
    Join Date
    Oct 2008
    Posts
    25
    Rep Power
    0

    Default

    It says in order to put links in my post I must have a post count of at least 20.

    So I'd appreciate some actual help and not trolling informing everyone about Internet ethics.

    Not to mention if I get more things, I would edit my post.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    So you call it "trolling" if someone posts information that helps you avoid pissing others off and will help you in the long run get more help? Good luck, you'll need it.

Similar Threads

  1. Help with an Array program please?
    By EternalSolitude in forum New To Java
    Replies: 3
    Last Post: 10-30-2008, 03:39 AM
  2. Replies: 1
    Last Post: 07-02-2008, 02:58 PM
  3. Array program help
    By adelgado0723 in forum New To Java
    Replies: 2
    Last Post: 04-16-2008, 02:19 PM
  4. Need help with my 1st array program
    By Phobos0001 in forum New To Java
    Replies: 5
    Last Post: 03-22-2008, 07:23 AM
  5. program help: Extracting words from a string
    By toad in forum New To Java
    Replies: 1
    Last Post: 11-04-2007, 07:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •