현재 배열 기반 프로그램을 프로그래밍하려고합니다. 우리는 직원 클래스를 만들고 5 명의 사용자 입력 직원 이름, 급여 및 성능 등급의 배열을 보유하고있는 테스터 기본 클래스를 만들어야합니다. 성과 등급은 제공된 인상 금액을 결정하는 데 사용됩니다. 나는 기본적으로 그것을했지만 Java 가상 머신이 실행 중일 때도 아무 일도 일어나지 않는다. 내가 오류를 위아래로 봤어, 아무도 내가 뭘 잘못하고있다 지적 할 수 있습니까?배열에 문제가 있습니다
직원 클래스public class Employee
{
private String employeeName;
private int salary;
private int performanceRating;
public Employee()
{
employeeName = "";
salary = 0;
performanceRating = 0;
}
public String getEmployeeName()
{
return employeeName;
}
public int getSalary()
{
return salary;
}
public int getPerformanceRating()
{
return performanceRating;
}
}
그리고 오류가이 프로그램은 System.in
읽 곳
import java.util.Scanner;
public class Tester
{
public static void main(String[] args)
{
Employee[] work = new Employee[5];
Scanner scanString = new Scanner(System.in);
Scanner scanInt = new Scanner(System.in);
String employeeName = "";
double salary = 0;
double performanceRating = 0;
String choice = scanString.nextLine();
while(choice.equals("yes"))
{
for(int i = 0; i < 5 ;i++)
{
System.out.println("What is the employee's name?");
employeeName = scanString.nextLine();
System.out.println("Enter Employee's salary");
salary = scanInt.nextInt();
System.out.println("Performance? 1 = excellent, 2 = good, 3 = poor");
performanceRating = scanInt.nextInt();
work[i] = new Employee();
}
for(int j = 0; j < 5; j ++)
if(work[j].getPerformanceRating() == 1)
{
salary = salary * 0.06;
System.out.println("Employee " + employeeName + " salary raised to " + salary);
}
else if(performanceRating == 2)
{
salary = salary * 0.04;
System.out.println("Employee " + employeeName + " salary raised to " + salary);
}
else if(performanceRating == 3)
{
salary = salary * 0.015;
System.out.println("Employee " + employeeName + " salary raised to " + salary);
}
else if(performanceRating < 5)
{
salary = salary;
System.out.println("Rating is off scale. No raise for emplyee " + employeeName);
}
System.out.println("Enter more employees? type 'yes' if you want to go again");
choice = scanString.nextLine();
}
System.out.println("Done");
}
}
생성 된'Employee' 필드를 설정하지 않고 getPerformanceRating' getPerformanceRating'을 지역 변수'performanceRating'와 혼합하면 급여가 실제로 갱신되지 않습니다 ('getSalary'는 변경되지 않습니다). 업데이트 된 급여를 인쇄하는 동안 더 많은 직원을 입력해야합니다. –