[英]Not sure what I am doing wrong
public class MainClass {
public static void main(String[] args) {
Employee employee = new Employee();
//Prompt for and then set the first name, last name, gender, dependents
employee.setFirstName(getInput("First Name: "));
employee.setLastName(getInput("Last Name: "));
employee.setGender(getInput("Gender: ").charAt(0));
employee.setDependents(getInput("Dependents: "));
employee.setAnnualSalary(getInput("Annual Salary: "));
//display divider
displayDivider("Employee Information");
//Display the employee information
employee.displayEmployee();
System.out.println("Number of Employees: " + Employee.getNumEmployees());
//Second Employee
Employee employee2 = new Employee("Mary", "Noia", 'F' , 5 , 24000.0);
//display divider
displayDivider("Employee Information");
employee2.displayEmployee();
System.out.println("Number of Employees: " + Employee.getNumEmployees());
} //end of main
public static String getInput(String inputType)
{
String input = "";
input = JOptionPane.showInputDialog("Enter the " + inputType);
return input;
}
public static void displayDivider(String outputTitle)
{
System.out.println("*********" + outputTitle + "********");
}//end of displayDvider
} //end of MainClass
這是我的結果。 但我想在最后得到員工人數:2
*********Employee Information********
First Name: Arooba
Last Name: Munir
Gender: F
Number of Dependents: 2
Annual Salary: $50,000.00
Weekly Pay: $961.54
Number of Employees: 1
*********Employee Information********
First Name: Mary
Last Name: Noia
Gender: F
Number of Dependents: 5
Annual Salary: $24,000.00
Weekly Pay: $461.54
Number of Employees: 1
我認為您應該將兩名員工放入一個數組列表並獲取數組列表的大小。 我不認為這會奏效
Employee.getNumEmployees();
所以也許是這樣的?
ArrayList<Employee> employees = new ArrayList();
employees.add(new Employee("Mary", "Noia", 'F' , 5 , 24000.0));
//etc...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.