class FizzBuzzProgram{ public static void main(String args[]){ for (int i = 0; i++ < 100; ) { System.out.println(new Number(i).checkMod3().checkMod5()); } } } interface Mod3Mod5Unchecked extends Mod5Unchecked { public Mod5Unchecked checkMod3(); } interface Mod5Unchecked { public Object checkMod5(); } class Number implements Mod3Mod5Unchecked{ private int no; public Number (int no) { this.no = no; } public Mod5Unchecked checkMod3() { return no % 3 == 0 ? new Fizz(no) : this; } public Object checkMod5() { return no % 5 == 0 ? new Buzz() : this; } public String toString() { return Integer.toString(no); } } class Fizz implements Mod5Unchecked{ private int no; public Fizz (int no) { this.no = no; } public Object checkMod5() { return no % 5 == 0 ? new FizzBuzz() : this; } public String toString() { return "Fizz"; } } class Buzz { public String toString() { return "Buzz"; } } class FizzBuzz { public String toString() { return "FizzBuzz"; } }
学生の皆さん、これがSIerの仕事です。