I just do not understand this syntax error I am receiving.

Fixing my syntax error in my project (decision structure project)

Page 1 of 1

6 Replies - 790 Views - Last Post: 28 March 2010 - 09:37 PM Rate Topic: -----

#1 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 07:32 PM

Okay guys I recently got a syntax error that I've never seen before and I need you guys to help me understand why I got it and how to fix it.

Here is my project code...
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 == NONPROFIT_CODE)
		{
			chosenManager = NONPROFIT_MANAGER;
			chosenRate = NONPROFIT_RATE;
		}
		else
			choiceIsGood = false;
	
	if (choiceIsGood)
	{
		scheduleEvent.setType(eventType);
		scheduleEvent.setManager(chosenManager);
		scheduleEvent.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");
	}
}
}



And here is the error I am receiving.

CreateEventObject.java:58: class, interface, or enum expected
}->
_



Is This A Good Question/Topic? 0
  • +

Replies To: I just do not understand this syntax error I am receiving.

#2 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 07:35 PM

You have an extra brace at the end of your program.
                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");
        }
}
} // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<


If that's your only error, then delete it and you should be fine.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 07:44 PM

And a main() method should have just a few lines (2 or 3)
it is in the constructor of your CreateEventObject that the job should be done if you want to be OO
Was This Post Helpful? 0
  • +
  • -

#4 zim1985  Icon User is offline

  • Grand Inquisitor
  • member icon

Reputation: 74
  • View blog
  • Posts: 568
  • Joined: 19-February 10

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 07:48 PM

View Postpbl, on 28 March 2010 - 05:44 PM, said:

And a main() method should have just a few lines (2 or 3)
it is in the constructor of your CreateEventObject that the job should be done if you want to be OO

pbl is correct. You should break up your code into methods so it is more OO. You main should be more like this:
public class Example
{
    public Example()
    {

    }

    public void method1()
    {
        // do work
    }

    public void method2()
    {
        // do work
    }

    public static void main(String[] args)
    {
        Example ex = new Example();
        ex.method1();
        ex.method2();
    }
}


Was This Post Helpful? 0
  • +
  • -

#5 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 09:01 PM

Well as I can see your point about my code not being very object oriented, this is the assignment I was given by my prof. She wants it done like it is stated in the textbook and I am simply following the textbook's directions.

I found a few silly mistakes (my typing skills suck).

I have revised my code a little bit and here is what I have so far...

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)
	{
		scheduleEvent.setType(eventType);
		scheduleEvent.setManager(chosenManager);
		scheduleEvent.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");
	}
}


And here are the errors I receive when I try to compile this...

[code]
CreateEventObject.java:50: cannot find symbol
symbol: variable scheduleEvent
location: class CreateEventObject
                scheduleEvent.setType(EventType);
                _
CreateEventObject.java:51: cannot find symbol
symbol: variable scheduleEvent
location: class CreateEventObject
                scheduleEvent.setManager(chosenManager);
                _
CreateEventObject.java:52: cannot find symbol
symbol: variable scheduleEventObject 
location: class CreateEventObject
                scheduleEvent.setRate(chosenRate); 
                _                
[/code ]


Was This Post Helpful? 0
  • +
  • -

#6 PFJ  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 21
  • Joined: 05-March 10

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 09:30 PM

Hello. In lines 50, 51 and 52 is 'scheduleEvent' supposed to be 'scheduledEvent'?
Was This Post Helpful? 1
  • +
  • -

#7 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

Re: I just do not understand this syntax error I am receiving.

Posted 28 March 2010 - 09:37 PM

Thanks so much man...so many times a problem stems from a stupid mistake like that I guess...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1