Results 1 to 3 of 3
  1. #1
    miss_peaches is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Last Question: Illegal Start of Expression

    Hello All,
    I am receiving an error message on the line where I begin using my constructor. The error points to the word "public" as being the cause for the error, but I don't know why! Do I need to move the constructor outside of the main method or something? Please help!!!!

    Java Code:
     * The IndividualInfo class implements an application that
     * simply stores and prints address and charitable donations for 5 individuals
     * and terminates. A constructor is used to initialize the individual
     * information, and a method within that class to calculate the yearly donation 
     * total. If a negative value is entered, the user is 
     * prompted to enter a positive value.
    class IndividualInfo {
    	// main method begins program execution
        	public static void main(String[] args) {
            //create scanner to obtain input from command window
    	java.util.Scanner input = new java.util.Scanner (;
    	String donorName; 	// Donor's name
    	String donorAddr;	// Donor's address
    	String donorCity;	// City where donor lives
    	String donorState;	// State where donor lives
    	int donorZipCode;	// Zipcode of owner's address
    	int numDonat;		// Number of donations
    	int amtDonat;		// Dollar amount of donations
    	int nameCounter;	// Number of names to be entered
    	double total;		// Total amount of donations this year
    	//constructor used to initialize info
    	public IndividualInfo (String, Int, Double);
    	     this.amtDonat= amount;
    	// processing phase
    	for (nameCounter = 1;nameCounter <= 5;nameCounter++) 
    	   System.out.print ("Enter the donor's name:"); //prompt
    	   name = input.nextLine(); // read donor's name from user input
      	   System.out.print ("Enter donor's address:"); //prompt
               address = input.nextLine(); // read address from user input
               System.out.print ("Enter donor's city:"); //prompt
               city = input.nextLine(); // read city from user input
    	   System.out.print ("Enter donor's state:"); // prompt
    	   state = input.nextLine(); // read state from user input
    	   System.out.print ("Enter donor's zipcode:"); //prompt
    	   zipCode = input.nextInt(); // read zipcode from user input
    	   System.out.print ("Enter the number of donations this year:"); 
    	   donations= input.nextInt(); // read number of donations 
    		while (amtDonat <= -1){
    		   System.out.print ("Number must be positive. Re-enter:");
    	   	   System.out.print ("Enter dollar amount of donations:"); 
    	           amount= input.nextInt(); // read donation amount 
    		while (numDonat<= -1){
    		   System.out.print ("Amount must be positive. Re-enter:")
    	    total = amount*donations;
    	   System.out.print ("The donor, whose name is"+ name);
    	   System.out.print ("and resides at"+ address);
    	   System.out.print ("in the city of"+ city);
    	   System.out.print ("in the state of"+ state);
    	   System.out.print ("with a zipcode of"+ zipCode);
    	   System.out.print ("has donated $"+ total);
    	   System.out.println ("this year!");	
    	} //end for
    	} // end main method
    } // end class IndividualInfo

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    You have your constructor inside the main method. Computer says no!

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Also, your constructor is weird, it takes 3 argument types, no formal parameters and uses a lot of variables.

    A constructor(and any method in java should have the formal parameters containing names)
    Java Code:
    public class X{
      public void someMethod(int x, int y, double a, String b){
        //do stuff with those variables

Similar Threads

  1. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 02:50 PM
  2. Illegal start of expression
    By Nigel in forum New To Java
    Replies: 5
    Last Post: 03-11-2011, 12:42 PM
  3. Need help with illegal start of expression
    By WhopperMan in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 02:58 AM
  4. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM
  5. Illegal Start of Expression
    By vince425 in forum New To Java
    Replies: 3
    Last Post: 10-18-2008, 07:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts