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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!