Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import chn.util.*;
- /**
- * @David Cortes
- * @12/16/14
- */
- public class LifeDriver
- {
- public static void main(String[] args)
- {
- //retrieving file
- FileInput inFile;
- String fileName = "life100.txt";
- inFile = new FileInput(fileName);
- //variables
- int x, y;
- int[][] board = new int[22][22];
- int[][] answer = new int[22][22];
- int count= 0;
- int row10 = 0;
- int col10 = 0;
- int firstInt = inFile.readInt();
- //cells corresponding to coordinates from text file are given a value of 1 to represent life
- while(inFile.hasMoreTokens())
- {
- x=inFile.readInt();
- y=inFile.readInt();
- board[x][y] = 1;
- }
- Life myLife = new Life();
- for(int loop = 0; loop <5; loop++)
- board = myLife.simulateLife(board);
- //traversing array to print it out. if a cell is living, prints our " *"
- for(int row = 1; row<=20; row++)
- {
- for(int col = 1; col<=20; col++)
- {
- if(board[row][col] ==1)
- {
- System.out.print("*");
- count++;
- }
- else
- System.out.print(" ");
- }
- System.out.println();
- }
- //finds number of cells living in row 10
- for(int col = 1; col<=20; col++)
- {
- if(board[10][col] ==1)
- row10++;
- }
- //finds number of cells living in col 10
- for(int row =1; row<=20; row++)
- {
- if(board[row][10] ==1)
- col10++;
- }
- //printing out total number of organisms living in total, in row 10, and in col 10
- System.out.println("Number in Row 10 -----> " + row10);
- System.out.println("Number in Column 10 ------> " + col10);
- System.out.println("total number of living organisms ----> " + count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment