//This class provides static methods to return College Student // year and class designations based on the Student's credits // public class CollegeYear { //Return a student's year-code based on their credits // 0 .. 29 : 1 30 .. 59 : 2 60 .. 89 : 3 90+ : 4 public static int code(int credits) { if ( credits < 0 ) throw new RuntimeException("Invalid # Credits"); int code; if ( credits < 30 ) // 0 .. 29 code = 1; else code = 4; return code; } //Return a student's year-name based on their credits // 0 .. 29: Freshman 30 .. 59: Sophomore // 60 .. 89: Junior 90+ : Senior public static String name(int credits) { String name = ""; switch ( code(credits) ) { case 1 : name = "Freshman"; case 2 : name = "Sophomore"; case 3 : name = "Junior"; case 4 : name = "Senior"; break; default: throw new RuntimeException("Invalid # Credits"); } return name; } //Return a student's classification based on their credits // 0 .. 59: Underclassman 60+ : Upperclassman public static String classification(int credits) { switch ( code(credits) ) { case 1 : return "Underclassman"; case 2 : return "Underclassman"; case 3 : return "Upperclassman"; case 4 : return "Upperclassman"; } throw new RuntimeException("Invalid # Credits"); } }