Results 1 to 4 of 4
- 11-17-2008, 01:29 AM #1
Member
- Join Date
- Oct 2008
- Posts
- 25
- Rep Power
- 0
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 01:47 AM.
-
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.
- 11-17-2008, 01:47 AM #3
Member
- Join Date
- Oct 2008
- Posts
- 25
- Rep Power
- 0
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.
-
Similar Threads
-
Help with an Array program please?
By EternalSolitude in forum New To JavaReplies: 3Last Post: 10-30-2008, 02:39 AM -
Java Program To Convert A Number In To Words With Decimals
By javanewbie in forum New To JavaReplies: 1Last Post: 07-02-2008, 01:58 PM -
Array program help
By adelgado0723 in forum New To JavaReplies: 2Last Post: 04-16-2008, 01:19 PM -
Need help with my 1st array program
By Phobos0001 in forum New To JavaReplies: 5Last Post: 03-22-2008, 06:23 AM -
program help: Extracting words from a string
By toad in forum New To JavaReplies: 1Last Post: 11-04-2007, 06:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks