So the gist of my program is that it will read some commands from a file and then perform certain operations judging by the commands. My problem is that my code isn't reading all of the lines of the txt document. Specifically, it reads the first four lines which I tested by previously inputting a print statement inside of the if statement that tests to see if the input = "P". Any help would be much appreciated.
Here is the txt document as well
P e1 10 5
P e2 19 5
P e3 11 5
P e4 18 5
R mouth 10 10 10 2
S nose 14 7 2
P p3 9 9
P p4 20 9
D
Y bad command
M p3 9 12
M p4 20 12
D
public static void main(String[] args) {
String filename = args[0];
File file = new File(filename);
Scanner input=null;
try {
input=new Scanner(file);
}
catch(java.io.FileNotFoundException ex) {
System.out.println("ERROR: Couldn't open file: " + file);
System.exit(1);
}
AsciiDisplay asciiDisplay= new AsciiDisplay();
while(input.hasNext()) {
if(input.next().equals("P")) {
String id=input.next();
int x=input.nextInt();
int y=input.nextInt();
Coordinate coordinate=new Coordinate(x,y);
Point point=new Point(id,coordinate);
asciiDisplay.addShape(point);
}
else if(input.next().equals("R")) {
String id=input.next();
int x=input.nextInt();
int y=input.nextInt();
int length=input.nextInt();
int height=input.nextInt();
Coordinate coordinate= new Coordinate(x,y);
Rectangle rectangle= new Rectangle(id,coordinate,length,height);
asciiDisplay.addShape(rectangle);
}
else if(input.next().equals("S")) {
String id=input.next();
int x=input.nextInt();
int y=input.nextInt();
int size=input.nextInt();
Coordinate coordinate= new Coordinate(x,y);
Square square = new Square(id,coordinate,size);
asciiDisplay.addShape(square);
}
else if(input.next().equals("M")) {
String id=input.next();
int x=input.nextInt();
int y=input.nextInt();
Coordinate coordinate= new Coordinate(x,y);
asciiDisplay.moveShape(id,coordinate);
}
else if(input.next().equals("E")) {
asciiDisplay.deleteAll();
}
else if(input.next().equals("D")) {
asciiDisplay.updateGrid();
asciiDisplay.printGrid();
}
else if(input.next().equals("X")) {
System.out.println("Invalid command: X");
}
}
}
}