skilletwaffles

LifeDriver

Jan 7th, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. import chn.util.*;
  2. /**
  3. * @David Cortes
  4. * @12/16/14
  5. */
  6.  
  7. public class LifeDriver
  8. {
  9. public static void main(String[] args)
  10. {
  11. //retrieving file
  12. FileInput inFile;
  13. String fileName = "life100.txt";
  14. inFile = new FileInput(fileName);
  15.  
  16. //variables
  17. int x, y;
  18. int[][] board = new int[22][22];
  19. int[][] answer = new int[22][22];
  20. int count= 0;
  21. int row10 = 0;
  22. int col10 = 0;
  23. int firstInt = inFile.readInt();
  24. //cells corresponding to coordinates from text file are given a value of 1 to represent life
  25. while(inFile.hasMoreTokens())
  26. {
  27. x=inFile.readInt();
  28. y=inFile.readInt();
  29. board[x][y] = 1;
  30. }
  31. Life myLife = new Life();
  32.  
  33. for(int loop = 0; loop <5; loop++)
  34. board = myLife.simulateLife(board);
  35.  
  36. //traversing array to print it out. if a cell is living, prints our " *"
  37. for(int row = 1; row<=20; row++)
  38. {
  39. for(int col = 1; col<=20; col++)
  40. {
  41. if(board[row][col] ==1)
  42. {
  43. System.out.print("*");
  44. count++;
  45. }
  46. else
  47. System.out.print(" ");
  48.  
  49. }
  50. System.out.println();
  51. }
  52.  
  53. //finds number of cells living in row 10
  54. for(int col = 1; col<=20; col++)
  55. {
  56. if(board[10][col] ==1)
  57. row10++;
  58. }
  59.  
  60. //finds number of cells living in col 10
  61. for(int row =1; row<=20; row++)
  62. {
  63. if(board[row][10] ==1)
  64. col10++;
  65. }
  66.  
  67. //printing out total number of organisms living in total, in row 10, and in col 10
  68. System.out.println("Number in Row 10 -----> " + row10);
  69. System.out.println("Number in Column 10 ------> " + col10);
  70. System.out.println("total number of living organisms ----> " + count);
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment