enum issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • noisepoet
    New Member
    • Feb 2007
    • 3

    enum issue

    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.");
    }
    }
    }
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by noisepoet
    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.");
    }
    }
    }
    Can we see the definition of 'WhoWins'? It looks like a class, but I think the implementation is off...

    Comment

    • noisepoet
      New Member
      • Feb 2007
      • 3

      #3
      Originally posted by sicarie
      Can we see the definition of 'WhoWins'? It looks like a class, but I think the implementation is off...
      I'm sorry, but I don't understand what you mean. I'm new to Java. I input the code as listed, and I'm getting "WhoWins cannot be resolved to a type." What does this mean? And how can I fix it?

      Comment

      • abctech
        New Member
        • Dec 2006
        • 157

        #4
        Originally posted by noisepoet
        I'm sorry, but I don't understand what you mean. I'm new to Java. I input the code as listed, and I'm getting "WhoWins cannot be resolved to a type." What does this mean? And how can I fix it?
        Hi,
        It means that just like you have a class 'Scoreboard' where is the definition of the class 'WhoWins'?

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by abctech
          Hi,
          It means that just like you have a class 'Scoreboard' where is the definition of the class 'WhoWins'?
          And if you already have that as an enum or class, you need to compile it first.

          Comment

          Working...