Hi. The program below is from Beginning Programming with Java for Dummies, from the section on declaring enum values. In Eclipse, the declaration WhoWins is coming up with an error (cannot assign a value). I've tried typing "enum" and "public enum" in front of it, but am getting the same error. I've changed the compliance to Java 6, which is what I'm using, but the error persists. Any ideas?
import java.util.Scann er;
class Scoreboard {
public static void main(String args[]) {
Scanner myScanner = new Scanner(System. in);
int hankees, socks;
WhoWins who;
System.out.prin t("Hankees and Socks scores? ");
hankees = myScanner.nextI nt();
socks = myScanner.nextI nt();
System.out.prin tln();
if (hankees > socks) {
who = WhoWins.home;
System.out.prin tln("The Hankees win :-)");
} else if (socks > hankees) {
who = WhoWins.visitor ;
System.out.prin tln("The Socks win :-(");
} else {
who = WhoWins.neither ;
System.out.prin tln("It's a tie:-|");
}
System.out.prin tln();
System.out.prin tln("Today's game is brought to you by:");
System.out.prin tln("SnitSoft, the number one software");
System.out.prin tln("vendor in the Hankeeville area.");
System.out.prin tln("SnitSoft is featured proudly in");
System.out.prin tln("Chapter 6. And remember, four out");
System.out.prin tln("of five doctors recommend SnitSoft");
System.out.prin tln("to their patients.");
System.out.prin tln();
if (who == WhoWins.home) {
System.out.prin tln("We beat 'em good. Didn't we?");
}
if (who == WhoWins.visitor ) {
System.out.prin tln("The umpire made an unfair call.");
}
if (who == WhoWins.neither ) {
System.out.prin tln("The game goes into overtime.");
}
}
}
import java.util.Scann er;
class Scoreboard {
public static void main(String args[]) {
Scanner myScanner = new Scanner(System. in);
int hankees, socks;
WhoWins who;
System.out.prin t("Hankees and Socks scores? ");
hankees = myScanner.nextI nt();
socks = myScanner.nextI nt();
System.out.prin tln();
if (hankees > socks) {
who = WhoWins.home;
System.out.prin tln("The Hankees win :-)");
} else if (socks > hankees) {
who = WhoWins.visitor ;
System.out.prin tln("The Socks win :-(");
} else {
who = WhoWins.neither ;
System.out.prin tln("It's a tie:-|");
}
System.out.prin tln();
System.out.prin tln("Today's game is brought to you by:");
System.out.prin tln("SnitSoft, the number one software");
System.out.prin tln("vendor in the Hankeeville area.");
System.out.prin tln("SnitSoft is featured proudly in");
System.out.prin tln("Chapter 6. And remember, four out");
System.out.prin tln("of five doctors recommend SnitSoft");
System.out.prin tln("to their patients.");
System.out.prin tln();
if (who == WhoWins.home) {
System.out.prin tln("We beat 'em good. Didn't we?");
}
if (who == WhoWins.visitor ) {
System.out.prin tln("The umpire made an unfair call.");
}
if (who == WhoWins.neither ) {
System.out.prin tln("The game goes into overtime.");
}
}
}
Comment