java - Trying to test Enum's method -
im trying manually test enum rotation method next() it's returning me nothing, null. when assign variable tester = rotation.cw0 , call method next(), method should return cw90 returning nothing. please smb take i've done wrong in code?
public class tester { public static void main(string[] args) { rotation tester = rotation.cw0; tester.next(); } } public enum rotation { cw0, cw90, cw180, cw270; // calling rot.next() return next enumeration element // representing next 90 degree clock-wise rotation after rot. public rotation next() { if(this == cw0) return cw90; else if(this == cw90) return cw180; else if(this == cw180) return cw270; else if(this == cw270) return cw0; return null; }
public class tester { public static void main(string[] args) { rotation tester = rotation.cw0; system.out.println(tester.next()); } } public enum rotation { cw0, cw90, cw180, cw270; public rotation next() { switch (this) { case cw0: return cw90; case cw90: return cw180; case cw180: return cw270; case cw270: return cw0; } return null; } }
Comments
Post a Comment