0

I am working on a problem for homework in a Java Programming course, and I am stuck. I will tell you upfront that I am by no means an expert, and don't know much about Java or Programming in general.

The issue that I am having is acutally not with a problem for my homework, but with an example from the book that I cannot seem to get to work. The section of the book is titled

WRITING AN APPLICATION THAT USES THE Event CLASS

The book has the following example in this section that it instructs the student to copy and try in their IDE to see how the concept of an Event class works:

import java.util.Scanner;

public class CreateEventObject
{

    public static void main(String[] args)
    {

    int eventType;
    String chosenManager = "";
    double chosenRate = 0;
    Event scheduledEvent = new Event();
    final int PRIVATE_CODE = 1;
    final int CORPORATE_CODE = 2;
    final int NONPROFIT_CODE = 3;
    final String PRIVATE_MANAGER = "Dustin Britt";
    final String CORP_MANAGER = "Carmen Lindsey";
    final String NONPROFIT_MANAGER = "Robin Armenetti";
    final double PRIVATE_RATE = 47.99;
    final double CORP_RATE = 75.99;
    final double NONPROFIT_RATE = 40.99;
    boolean choiceIsGood = true;

    Scanner input = new Scanner(System.in);
    System.out.println("What type of event are you scheduling?");
    System.out.print("Enter " + PRIVATE_CODE + " for private, " + CORPORATE_CODE + " for corporate, or " + NONPROFIT_CODE + " for nonprofit... ");
    eventType = input.nextInt();

    if(eventType == PRIVATE_CODE)
    {
        chosenManager = PRIVATE_MANAGER;
        chosenRate = PRIVATE_RATE;
    }
    else
        if(eventType == CORPORATE_CODE)
        {
            chosenManager = CORP_MANAGER;
            chosenRate = CORP_RATE;
        }
        else
            if(eventType == NONPROFIT_CODE)
            {
                chosenManager = NONPROFIT_MANAGER;
                chosenRate = NONPROFIT_RATE;
            }
            else
                choiceIsGood = false;

    if(choiceIsGood)
    {
        scheduledEvent.setType(eventType);
        scheduledEvent.setManager(chosenManager);
        scheduledEvent.setRate(chosenRate);
    }
    else
        System.out.println("You entered " + eventType + " which is invalid.");

    System.out.println("Scheduled event:");
    System.out.println("Type: " + scheduledEvent.getType() + " Manager: " + scheduledEvent.getManager() + " Rate: " + scheduledEvent.getRate() + " per hour");
    }

}

When I try to compile the code above, I get the following error from the IDE:

CreateEventObject.java:12: error: cannot find symbol
    Event scheduledEvent = new Event();
    ^
  symbol:   class Event
  location: class CreateEventObject
CreateEventObject.java:12: error: cannot find symbol

It says the class Event is the issue, but according to the book, that's a valid class...

I am using JGRASP on Windows 7 Professional 64bit and JDK 1.70.

I think it is weird that an example from the book doesn't compile correctly, but it isn't. I am probably missing something really easy, but I can't see anythign that is wrong.

Any help or direction would be appreciated. Thanks in advance for the help.

2
  • 3
    What is an Event ? I'm guessing this class is implemented earlier in the chapter / book - you need that code in your project. Commented Nov 6, 2011 at 16:42
  • 8
    The problem is that the Event class can not be found. Did you create the Event class from the previous chapter "Create an Event class to use in a decision-making application"? Both class must be in the same package or you will need to add an import statement for the Event class. Commented Nov 6, 2011 at 16:42

2 Answers 2

3

You are trying to use those methods:

scheduledEvent.setType(eventType);
scheduledEvent.setManager(chosenManager);
scheduledEvent.setRate(chosenRate);

that don't belong to awt Event class. So probably in your book there is somewhere described an Event class: find it then:

  1. create a class with the implementation described in your book
  2. Add that class to CreateEventObject's package or put it inside another package and then import it:

    import your.package.name.Event;
    
Sign up to request clarification or add additional context in comments.

3 Comments

You don't need to specify the package if the Event is in the same package as CreateEventObject. But I suspect he didn't create the Event class from the book.
Erm, no, because the methods he's calling aren't part of the java.awt.Event class. (This was my initial answer too until I looked ... then deleted it ;) )
@Brian Roach: Yes, you are right.. I was just editing my answer. thanks
1

Event is present in java.awt.Event. You have to import it.

http://download.oracle.com/javase/1.4.2/docs/api/java/awt/Event.html

5 Comments

Erm, no, because the methods he's calling aren't part of the java.awt.Event class. (This was my initial answer too until I looked ... then deleted it ;) )
Aha. These: scheduledEvent.setType(eventType); scheduledEvent.setManager(chosenManager); scheduledEvent.setRate(chosenRate);
WTF! I get downvoted for the same thing that gets upvoted above! And I spot the same thing (5 minutes before, in the comment above) what appears as a edit in the above answer, that also earned an upvote. Funny eh?
don't hate me..that's not my fault.. I give you my +1 vote because I think that it's a bit unfair. Anyway, with the edit I correct my previous wrong answer.. so do it you too or remove it.
@Heisenbug absolutely not hating you. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.