| | |
Help with hw...
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2009
Posts: 1
Reputation:
Solved Threads: 0
AHHH so i've been writing this code with my teachers help. IT will now be able to get 1 coordinate, but i want it to get teh same number of coordinates, i set my shipsize to.. waht can i do...my teacher said I could do a loop... but.... i couldnt get it to work....( this is jsut part of the code) you dotn the otehrs...
java Syntax (Toggle Plain Text)
import java.util.ArrayList; public class GameBoard { private boolean[][] i = new boolean[10][10]; boolean spotIsTaken = true; public ArrayList<String> placeShip(int shipSize) { System.out.println(shipSize); String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"}; int row =(int)(Math.random()*10); int column =(int)(Math.random()*10); while(spotIsTaken) { if(i[row][column]) { row =(int)(Math.random()*10); column =(int)(Math.random()*10); } else { spotIsTaken = false; } } for (int i = ) ArrayList<String> points = new ArrayList<String>(); points.add(letters[row] + (column + 1)); System.out.println(letters[row]+ (column + 1)); return points; } } // Returns an ArrayList of coordinates // where a ship of shipSize can be placed // Example: placeShip(3) // could return { b3, b4, b5 }
Last edited by peter_budo; 29 Days Ago at 4:25 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
![]() |
Other Threads in the Java Forum
- Previous Thread: working with Java GUI
- Next Thread: playing PIG
| Thread Tools | Search this Thread |
-xlint add android api applet application array arrays automation bi binary blackberry bluetooth chat class classes client code compile compiler component converter database digit eclipse equation error event exception fractal freeze functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide idea image input int integer j2me java javame javaprojects jetbrains jni jpanel jtable julia learningresources linux list login loop main map method methods mobile myregfun netbeans newbie nonstatic notdisplaying page pearl print problem program programming project qt recursion scanner screen scrollbar server set size sms sort spamblocker sql string superclass swing system thread threads time tree variablebinding windows xor





