| | |
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; 32 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 |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows





