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
答案 0 :(得分:0)
我认为你应该把两个员工都放到一个arraylist并获得arraylist的大小。我不认为这会起作用
Employee.getNumEmployees();
那么也许是这样的?
ArrayList<Employee> employees = new ArrayList();
employees.add(new Employee("Mary", "Noia", 'F' , 5 , 24000.0));
//etc...