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

    Angry Another Illegal Start of Expression

    Hello, I know you're probably sick of the same question being asked, and I'm sick of having to ask but here goes....I keep getting this error message <illegal start of expression> under each instance of the word "Private". I've tried making sure my braces match up, ";" are in place, tried moving main method to after variables, and tried adding the word "static" to each instance of private, but still nothing. Here is the entire code for your review.Please help!

    Java Code:
    class AddressBookApp2 {
    	// main method begins program execution
        	public static void main(String[] args) {
    
    	 private String donorName; // Donor's name
    	 private String donorAddr; // Donor's address
    	 private String donorCity; // City where donor lives
      	 private String donorState;// State where donor lives
    	 private int donorZipCode; // Zipcode of owner's address
    	 private int numDonat;	   // Number of donations
    	 private int amtDonat;	   // Dollar amount of donations
    	 private double total;	   // Total amount of donations this year
    	 int nameCounter = 1;	   // Number of names to be entered
    
    	//create scanner to obtain input from command window
    	java.util.Scanner input = new java.util.Scanner (System.in);
    	
    	// 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:"); 
    	   numDonat= 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:"); 
    	           amtDonat= input.nextInt(); // read donation amount
    
    		while (numDonat<= -1){
    		   System.out.print ("Amount must be positive. Re-enter:")
    		  }
    	    total = amtDonat*numDonat;
    	
    	   System.out.print ("The donor, whose name is"+ donorName);
    	   System.out.print ("and resides at"+ donorAddr);
    	   System.out.print ("in the city of"+ donorCity);
    	   System.out.print ("in the state of"+ donorState);
    	   System.out.print ("with a zipcode of"+ donorZipCode);
    	   System.out.print ("has donated $"+ Total);
    	   System.out.println ("this year!");	
    	  
    	} //end for
    
    	} // end main method
    
    } // end class AddressBookApp2
    Last edited by miss_peaches; 05-11-2011 at 05:44 PM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    6

    Default

    local variables can not have an access modifier!
    private String donorName; --> String donorName;

    But
    name = input.nextLine(); // read donor's name from user input
    and so on....where do you have declared name,address and so on...??

  3. #3
    miss_peaches is offline Member
    Join Date
    Apr 2011
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    local variables can not have an access modifier!
    private String donorName; --> String donorName;

    But
    name = input.nextLine(); // read donor's name from user input
    and so on....where do you have declared name,address and so on...??
    My bad. I just changed the name from "name" to "donorName" and so forth but i forgot to change it in the system.out.print segment. The error came before the change, but I'll update the code. Thx for pointing that out

Similar Threads

  1. illegal start of expression
    By minusten in forum New To Java
    Replies: 1
    Last Post: 05-03-2011, 05:46 AM
  2. Illegal Start of Expression
    By Tyre in forum New To Java
    Replies: 20
    Last Post: 04-15-2011, 03:50 PM
  3. Need help with illegal start of expression
    By WhopperMan in forum New To Java
    Replies: 4
    Last Post: 10-10-2010, 03:58 AM
  4. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 09:43 AM
  5. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 10:12 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
  •