public void printFullReport(PrintStream report) { /*Compile error, "printOn not understood by Object for (Object each: this.list) each.printOn(report); //<---------- compile error here */ report.println("College: " + this.name); report.println("Apologies, printing of list is not yet supported"); report.println("Objects do not understand \"printOn\""); }
public void printFullReport(PrintStream report) {
/*Compile error, "printOn not understood by Object
for (Object each: this.list)
each.printOn(report); //<---------- compile error here
*/
report.println("College: " + this.name);
report.println("Apologies, printing of list is not yet supported");
report.println("Objects do not understand \"printOn\"");
}
public void printFullReport(PrintStream stream) {
//printOn is understood by Printable dudes, so we're good to go
stream.println("College: " + this.name);
stream.println("I have a list of entities of size: " + this.list.size());
stream.printf("%nHere is my list:%n%n");
for (Printable each: this.list)
each.printOn(stream);
}
public void printOn(PrintStream report)
public interface Printable {
public void printOn(PrintStream report);
}
#1public class Classroom2 implements Printable { private int roomNumber; public Classroom2(int aRoomNumber) { this.roomNumber = aRoomNumber; } public int getRoomNumber() { return roomNumber; }#2public void printOn(PrintStream report) { report.println("I am Classroom: " + getRoomNumber()); } }
#1public void printFullReport(PrintStream stream) { //printOn is understood by Printable dudes, so we're good to go stream.println("College: " + this.name); stream.println("I have a list of entities of size: " + this.list.size()); stream.printf("%nHere is my list:%n%n"); for (Printable each: this.list)#2each.printOn(stream); }