这是我不断得到的错误,并且不确定如何纠正错误。
线程中的异常" main" java.lang.RuntimeException:无法编译 源代码 - 非法开始表达 salescommission.SalesCommission.main(SalesCommission.java:27)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salescommission;
/**
*
* @author Michael
*/
public class SalesCommission {
/**
* @param args the command line arguments
*/
public static void main(String[] args){
// public class SalesCommission {
// fixed salary variable
double fixedSalary;
// variable of the value of sale person's annual sales
double annualSales;
//the commission earned
double commission;
private final double annualSales;
private double commission;
private double fixedSalary;
public SalesCommission(double annualSales){
this.annualSales=annualSales;
double commission = 0.25*annualSales; //The current commission 25% of total sales.
int fixedSalary = 75000; // set fixed salary is 75000$
}
public double getTotalAnnualCompensation(){// calculate The total annual compensation is the fixed salary plus the commission earned
return fixedSalary+commission;
}
}
答案 0 :(得分:1)
双重佣金后你只会忘记一个“}”; : - )
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package salescommission;
/**
*
* @author Michael
*/
public class SalesCommission {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// public class SalesCommission {
// fixed salary variable
double fixedSalary;
// variable of the value of sale person's annual sales
double annualSales;
//the commission earned
double commission;
}
private final double annualSales;
private double commission;
private double fixedSalary;
public SalesCommission(double annualSales) {
this.annualSales = annualSales;
double commission = 0.25 * annualSales; //The current commission 25% of total sales.
int fixedSalary = 75000; // set fixed salary is 75000$
}
public double getTotalAnnualCompensation() {// calculate The total annual compensation is the fixed salary plus the commission earned
return fixedSalary + commission;
}
}
但是代码没有意义,你必须在main方法中运行一个方法:o)
答案 1 :(得分:0)
将类变量和方法定义放在main方法之外然后它应该可以工作。
答案 2 :(得分:0)
这不是Netbeans错误......你的主要方法没有封闭的括号:)
public static void main(String[] args) {
// public class SalesCommission {
// fixed salary variable
double fixedSalary;
// variable of the value of sale person's annual sales
double annualSales;
//the commission earned
double commission;
}