Results 1 to 3 of 3
- 05-12-2011, 04:56 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 15
- Rep Power
- 0
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 (System.in); 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.donorName=name; this.donorAddr=address; this.donorCity=city; this.donorState=state; this.donorZipCode=zipCode; this.numDonat=donations; this.amtDonat= amount; this.nameCounter=counter; this.total=total; } // 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
- 05-12-2011, 05:02 AM #2
You have your constructor inside the main method. Computer says no!
- 05-12-2011, 06:08 AM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
-
Illegal Start of Expression
By Tyre in forum New To JavaReplies: 20Last Post: 04-15-2011, 02:50 PM -
Illegal start of expression
By Nigel in forum New To JavaReplies: 5Last Post: 03-11-2011, 12:42 PM -
Need help with illegal start of expression
By WhopperMan in forum New To JavaReplies: 4Last Post: 10-10-2010, 02:58 AM -
Illegal Start of expression
By Macca07 in forum New To JavaReplies: 3Last Post: 11-23-2009, 08:43 AM -
Illegal Start of Expression
By vince425 in forum New To JavaReplies: 3Last Post: 10-18-2008, 07:41 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks