Question
My code should tell me which major is associated with each division but I keep getting an error. Here is my code, the main method
My code should tell me which major is associated with each division but I keep getting an error. Here is my code, the main method is in MajorsTest.java and the constructor is in Majors.java:
MajorsTest.java:
import java.util.Scanner;
public class MajorsTest {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enumeration values are ACC, CHEM, CIS, ENG, HIS, PHYS.");
System.out.print("Please enter a major: ");
String major = in.next();
Majors majors = new Majors();
System.out.println(major + " is in " + majors.getDivision(Majors.valueOf(major.toUpperCase())));
}
}
Majors.java:
public class Majors {
enum Major{ACC,CHEM,CIS,ENG,HIS,PHYS
}
public String getDivision(Major major) {
if(major == Major.ACC || major == Major.CIS) {
return "Business";
} else if(major == Major.CHEM || major == Major.PHYS) {
return "Science";
} else {
return "Humanities";
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started