我完全被难住了。我是java编程的初学者。我有以下代码,但无法理解为什么在我的公共静态无效行上出现“非法类型开始”错误。请帮忙。
另外:我怎样才能将这个不断增长的程序分成多个类?
`package annual.salary;
/*Annual Salary Calculator
* Version 1.1
*/
import java.util.Scanner; //Program uses Scanner
import java.text.DecimalFormat; //Configures output for dollar amounts
import java.util.InputMismatchException; //Checks for invalid user input
public class AnnualSalary
{
public void displayMessage()
{
//display intro message to calculator
System.out.println("Annual Compensation Calculator");
}
public static void main (String[] args,)
{
double salary; //This is the annual sales value
double rate; //Commission rate once minimum sales reached
double commission; //This is the amount of commision made
double pay; //Salesperson's total pay
double sales; //annual sales, prompted user input
double incentive; //bonus rate once sales target is exceeded
double max; //sets maximum sales amount to calculate for potential earnings table
boolean isValidNumber=false; //default flag for numeric sales input
Scanner input = new Scanner( System.in ); //allows user input from command window
DecimalFormat dollar = new DecimalFormat("#,##0.00");
salary = 50000.00;
rate = 0.05;
incentive = 0.0625;
sales = 0;
max = sales * 1.5;
System.out.println(" Enter The Annual Sales "); //prompt for input from user
while(!isValidNumber) //Continue to prompt user until a valid number is entered
{
try //try/catch block to handle invalid characters.
{
sales = input.nextDouble(); //Read number from user, if alpha character is keyed then an exception is thrown
isValidNumber = true; //Set our flag so we can exit the loop
}
catch(InputMismatchException ioe) //Catch input not matching excpected type.
{
System.out.println("Please enter a numeric value."); //re-prompt user
input.next(); //If Scanner translates successfully it advances, however if it fails it must be manually advanced.
}
}
while (sales < 96000.00) //conditional statement for sales below 80% of goal
{
pay = salary ;
System.out.println("Total Annual Compensation is $"+dollar.format(pay));
}
while (sales >= 96000.00 && sales <= 120000.00) //conditional statement for sales 80%-100% of goal
{
commission = sales * rate;
pay = commission + salary;
System.out.println("Total Annual Compensation is $"+dollar.format(pay));
}
while (sales > 120000.00) //conditional statement for sales exceeding goal
{
commission = sales * incentive;
pay = commission + salary;
System.out.println("For: $" + sales + " The Total Compensation is: $" +dollar.format(pay));
}
while(sales < max) //This sets the while loop to start at minimum & end at the max
{
sales = sales + 5000;
if (sales < 96000.00) //conditional statement for sales below 80% of goal
{
pay = salary;
}
else if (sales >= 96000.00 && sales <= 120000.00)
{
commission = sales * rate;
pay = commission + salary;
}
while (sales > 120000.00) //conditional statement for sales exceeding goal
{
commission = sales * incentive;
pay = commission + salary;
System.out.println("For: $" + sales + " The Total Compensation is: $" +dollar.format(pay));
}
} //Ends the body of the while loop.
}
} //end calculator'