在文件错误中找不到主要方法,小程序或MIDlet

时间:2016-04-13 21:08:21

标签: java debugging

我正在尝试为我正在进行的java类完成此程序,并且编译完全正常但是当我运行该程序时它会说"文件中没有找到主要方法,applet或MIDlet。 #34;谁能告诉我为什么会这样?谢谢。

public class BabysittingJob {

private int jobNumber;
private int babysitterCode;
private String babysitter;
private int childrenNumber;
private int hoursWorked;
private double fee;

public BabysittingJob(int year, int sequentialNumber, int babysitterCode, int childrenNumber, int hoursWorked, String babysitter) {
    year = year % 2000;
    this.childrenNumber = childrenNumber;
    this.hoursWorked = hoursWorked;
    this.babysitterCode = babysitterCode;
    this.jobNumber = ((year * 10000) + sequentialNumber);

    if (babysitterCode == 1) {
        this.babysitter = "Cindy";
    } else if (babysitterCode == 2) {
        this.babysitter = "Greg";
    } else if (babysitterCode == 3) {
        this.babysitter = "Marcia";
    }

    if (babysitterCode == 1) {
        this.fee = hoursWorked * 7 * childrenNumber;
    } else if (babysitterCode > 1 && childrenNumber == 1) {
        this.fee = hoursWorked * 9 * childrenNumber;
    } else if (babysitterCode > 1 && childrenNumber > 1) {
        this.fee = (hoursWorked * 9) + ((--childrenNumber) * hoursWorked * 4);

    }
}

}

1 个答案:

答案 0 :(得分:0)

您需要添加一个main方法。这就是编译器的开始。在同一个类中,您可以创建一个表示public static void main(string args []){}的方法。那个或在一个带有main方法的单独类中,你可以用BabysittingJob创建这个类的实例varName = new BabysittingJob(int,int,int,int,int,string);