rendered paste bodyimport java.io.*;
import java.util.Scanner;
public class ObjectEraser
{
private final static int MAXROW = 20;
private final static int MAXCOL = 20;
private final static char FOUND= '@';
int x,y;
boolean cleared = true;
char current = ' ';
public void getObjects(char [][] objs)
{
try //trys to find file
{
FileReader reader = new FileReader("digital.txt");
Scanner sf = new Scanner(reader);
for(int x = 1; x<20; x++)
{
for(int y = 1; y<20; y++)
{
objs[x][y] = '-';
}
}
while(sf.hasNext())
{
objs[sf.nextInt()][sf.nextInt()] = FOUND;
}
sf.close();
}
catch(IOException e)
{
System.out.println("File problems");
}
}
public void printObjects(char[][] objs) throws IOException
{
System.out.println("12345678901234567890");
for(int x = 1; x<20; x++)
{
System.out.print(x%10);
for(int y = 1; y<20; y++)
{
System.out.print(objs[x][y]);
}
System.out.println();
}
}
public int findX(char[][] objs)
{
{
for(int x = 0; x<21; x++)
{
for(int y = 0; y<21; y++)
{
if(objs[x][y] == FOUND)
return x;
}
}
return -1;
}
}
public int findY(char[][] objs)
{
for(int x = 0; x<21; x++)
{
for(int y = 0; y<21; y++)
{
if(objs[x][y] == FOUND)
return y;
}
}
return -1;
}
public void doErase(char[][] objs, int x, int y) throws IOException
{
if(x==MAXROW || y ==MAXCOL || objs[x][y] == '-' || y == 0 || x == 0);
else
{
objs[x][y] = '-';
doErase(objs, x+1, y);
doErase(objs, x-1, y);
doErase(objs, x, y+1);
doErase(objs, x, y-1);
}
}
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
ObjectEraser erase = new ObjectEraser();
char[][] objs = new char[MAXCOL + 1][MAXROW + 1];
String cont = "y";
int x, y;
erase.getObjects(objs);
erase.printObjects(objs);
x = erase.findX(objs);
y = erase.findY(objs);
System.out.println();
while(cont.equalsIgnoreCase("y"))
{
x = erase.findX(objs);
y = erase.findY(objs);
if(x == 20)
{
System.out.println("No objects present");
cont = "n";
}
else
{
erase.doErase(objs,x,y);
erase.printObjects(objs);
System.out.print("Would you like to continue? ");
cont = scan.next();
System.out.println();
}
}
}
}