Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago