Help with hw...

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2009
Posts: 1
Reputation: icreamed is an unknown quantity at this point 
Solved Threads: 0
icreamed icreamed is offline Offline
Newbie Poster

Help with hw...

 
0
  #1
29 Days Ago
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...

  1. import java.util.ArrayList;
  2.  
  3. public class GameBoard
  4. {
  5. private boolean[][] i = new boolean[10][10];
  6.  
  7. boolean spotIsTaken = true;
  8.  
  9. public ArrayList<String> placeShip(int shipSize)
  10. {
  11. System.out.println(shipSize);
  12.  
  13. String[] letters = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"};
  14.  
  15. int row =(int)(Math.random()*10);
  16. int column =(int)(Math.random()*10);
  17.  
  18.  
  19. while(spotIsTaken)
  20. {
  21. if(i[row][column])
  22. {
  23. row =(int)(Math.random()*10);
  24. column =(int)(Math.random()*10);
  25. }
  26. else
  27. {
  28. spotIsTaken = false;
  29. }
  30.  
  31. }
  32.  
  33.  
  34. for (int i = )
  35.  
  36.  
  37.  
  38.  
  39. ArrayList<String> points = new ArrayList<String>();
  40.  
  41. points.add(letters[row] + (column + 1));
  42.  
  43.  
  44. System.out.println(letters[row]+ (column + 1));
  45.  
  46. return points;
  47. }
  48.  
  49. }
  50.  
  51.  
  52. // Returns an ArrayList of coordinates
  53. // where a ship of shipSize can be placed
  54. // Example: placeShip(3)
  55. // 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)
Reply With Quote Quick reply to this message  
Reply

Message:



Other Threads in the Java Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC