Program implements toString

This commit is contained in:
Imbus 2024-04-16 15:28:20 +02:00
parent b97d09ac5b
commit 4b11ef49e7
2 changed files with 11 additions and 6 deletions

View file

@ -15,11 +15,7 @@ public class Main {
computer.run();
memory.dump();
// Print the program
System.out.println("Program:");
for (Instruction instruction : program) {
System.out.println(instruction);
}
System.out.println(program);
System.out.println("Completed");
}

View file

@ -3,4 +3,13 @@ package hatelace;
import java.util.ArrayList;
// This is simply an intermediate class to comply with the specified API requirements.
public abstract class Program extends ArrayList<Instruction> {}
public abstract class Program extends ArrayList<Instruction> {
public String toString() {
StringBuilder builder = new StringBuilder();
for (Instruction instruction : this) {
builder.append(instruction.toString());
builder.append("\n");
}
return builder.toString();
}
}