import java.awt.DisplayMode;
import java.util.Scanner;
public class mainClass {
private static String[][] Cell;
final static String normal="white";
final String abnormal="green";
final static String temp="red";
public static void main(String []args){
Scanner w = new Scanner(System.in);
Cell c1 = new Cell();
//please implement the main method
System.out.println("Please enter the size of the array: ");
int size = w.nextInt();
displayArray();
c1.initializeColor(size);
System.out.print("Please enter the the cordinates to chek: ");
System.out.println("r: ");
int x = w.nextInt();
System.out.println("c: ");
int y = w.nextInt();
countCells( x, y);
}//end main
/*
*The method countCells is a RECURSIVE method whose job is to find
*how many cells are in the same blob as a given cell (i.e cell with
*specified coordinates x and y). The variable int size represents the
*size of the two-dimensional array. This value would have been provided
*by the user at the beginning of the main method.
*Do NOT make any changes to the method declartion.
*/
public static int countCells( int x, int y){
int count=0;
for(int x1=0; x1<Cell.length; x1++)
for(int y1=0; y1<Cell.length; y1++){
Cell[x][y]=normal;
}
for(int x1=0; x1<Cell.length; x1++)
for(int y1=0; y1<Cell.length; y1++){
if(getblobsize(x,y, Cell) > 0)
count++;
}
System.out.print("The number of blobs: " + count);
return count;
}//countCells()
private static int getblobsize(int r, int c, String Cell[][]) {
if(r<0 || r>=Cell.length || c<0 || c>=Cell.length){
return 0;
}
if(Cell[r][c] == temp || Cell[r][c] == normal){
return 0;
}
else{
int time=1;
time += getblobsize( r - 1, c + 1, Cell);
time += getblobsize( r, c + 1, Cell);
time += getblobsize( r + 1, c + 1, Cell);
time += getblobsize(r + 1, c, Cell);
time += getblobsize( r + 1, c - 1, Cell);
time += getblobsize( r, c - 1, Cell);
time += getblobsize( r - 1, c - 1, Cell);
time += getblobsize( r - 1, c, Cell);
return time;
}
}
/*
* The method diplayArray is provided for you to call when you want to
* display your array on the screen. You should know how and when to
* to use this method in your program by looking at its declaration and
* the expected output.Do NOT make any changes to this method.
*/
public static void displayArray(Cell [][] ,int size){
for(int i=0;i<size;i++){
System.out.println();
System.out.print("-");
for(int j=0;j<size;j++){
System.out.print("-+");
}
System.out.println();
for (int j=0;j<size;j++){
String color=cells[i][j].getColor();
System.out.print("|"+color.charAt(0));
}
System.out.print("|");
}//outer
System.out.print("\n-");
for(int j=0;j<size;j++){
System.out.print("-+");
}
}//end displayArray()
}//end mainClass