Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//chapter 9;Joyce Farrell;8th ed;Java programming //output //simple code Create

ID: 3664957 • Letter: #

Question

//chapter 9;Joyce Farrell;8th ed;Java programming

//output

//simple code

Create a class name Majors that includes an enumeration forl the six majors offered by a college as follows: ACC, CHEM, CIS, ENG, HIS, PHYS. Display the enumeration values for the user, then prompt the user to enter a major. Display the college division in which the major falls. ACC and CIS are the Business Division, CHEM and PHYS are in the Science Division, and ENG and HIS are in the Humanities Division. Save the file as Majors.Java

Explanation / Answer

public interface Enumeration<E>
An object that implements the Enumeration interface generates a series of elements, one at a time. Successive calls to the nextElement method return successive elements of the series.
For example, to print all elements of a Vector<E> v:

for (Enumeration<E> e = v.elements(); e.hasMoreElements();)
System.out.println(e.nextElement());
Methods are provided to enumerate through the elements of a vector, the keys of a hashtable, and the values in a hashtable. Enumerations are also used to specify the input streams to a SequenceInputStream.

NOTE: The functionality of this interface is duplicated by the Iterator interface. In addition, Iterator adds an optional remove operation, and has shorter method names. New implementations should consider using Iterator in preference to Enumeration.

Program:

import java.util.Enumeration;

public class Majors
{

enum Choice { ACC, CHEM, CIS, ENG, HIS, PHYS }

public static void main(String[] args)
{
System.out.printf("Enter 1 for ACC,2 for CHEM,3 for CIS,4 for ENG,5 for HIS,6 for PHYS ");
Scanner input = new Scanner(System.in);
choice = input.nextInt();
switch(choice) {
case 1:
case 2:
System.out.println("Business Division selected");
break;
case 3:
case 4:
System.out.println("Science Division selected");
break;
case 5:
case 6:
System.out.println("Humanities Division selected");
break;
}
}
}