2013-10-24 3 views
-1

직원 연령의 값을 사용하는 데 문제가 있으며 primeagechecker가 있습니다. 직원은 연령 자체의 가치가 있습니다. Primeagechecker는 소수인지 아닌지 만 확인합니다. 그런 다음 println 명령에서 "나이가 소수입니다." 나는 자바 인이 아니다. 나는 자바로 초보자이다. 연령 체크를 할 때 항상 결과는 거짓이다. 도와 주셔서 감사합니다.직원 및 각 직원의 프라임 나이를 확인하십시오.

여기 내 코드입니다.

public class Employee { 
    String name; 
    boolean check; 
    int age; 
    Department department; 
    public ArrayList<Employee> emplo; 

    static Employee emp1 = new Employee(Department.Accounting,"Counting Guru",55); 
    static Employee emp2 = new Employee(Department.Accounting,"Counting Pro", 45); 
    static Employee emp3 = new Employee(Department.Accounting,"Counting Savvy", 40); 
    static Employee emp4 = new Employee(Department.Accounting,"Counting Novice", 25); 
    static Employee emp5 = new Employee(Department.Marketing,"Sales Guru", 50); 
    static Employee emp6 = new Employee(Department.Marketing,"Sales Pro", 48); 
    static Employee emp7 = new Employee(Department.Marketing,"Sales Savvy", 38); 
    static Employee emp8 = new Employee(Department.Human_Resources,"Hiring Guru", 58); 
    static Employee emp9 = new Employee(Department.Human_Resources,"Hiring Pro", 47); 
    static Employee emp10 = new Employee(Department.Information_Systems,"Hacking Pro", 46); 
    static Employee emp11 = new Employee(Department.Information_Systems,"Hacking Guru", 51); 
    static Employee emp12 = new Employee(Department.Information_Systems,"Hacking Savvy", 38); 
    static Employee emp13 = new Employee(Department.Information_Systems,"Hacking Novice", 23); 

    Employee(Department department,String name, int age) 
    { 
     this.department = department; 
     this.name = name; 
     this.age = age; 
    } 

    public int getAge() 
    { 
     return age; 
    } 

    public String getName() 
    { 
     return name; 
    } 

    public boolean GetChecker() 
    { 
     return check; 

    } 

    public void addEmplo(Employee x){ 
     if (emplo.isEmpty()) 
     { 
      emplo.add(x); 
     } 
     else 
     { 
      int i; 
      for (i = 0;i <emplo.size(); ++i){ 
       if(emplo.get(i).getAge() > x.getAge()){ 
        emplo.add(i,x); 
        break; 
       } 
      } 

      if (i == emplo.size()){ 
       emplo.add(x); 
      } 
     } 
     } 

    public ArrayList<Employee> getEmplo(){ 
     return emplo; 
    } 

    public String toString(){ 
     StringBuffer sb = new StringBuffer(); 
     sb.append(getDept(department)); 
     sb.append("\t"); 
     sb.append(getName()); 
     sb.append("\t"); 
     sb.append(getAge()); 
     sb.append("\t"); 
     sb.append(GetChecker()); 

     return sb.toString(); 
    } 

    private Department getDept(Department department){ 
     return department; 
    } 

} 





public class PrimeAgeChecker{ 

    Employee age; 

    PrimeAgeChecker(Employee age) 
    { 
     this.age = age; 
    } 

    public boolean check(){ 

     boolean status = false; 

     for (int a = 2; a < age; ++a){ 
      if (age % a == 0) 
      { 
       status = true; 
      } 
     } 

     return status; 

    } 
} 

답변

0

귀하의 프라임 검사기에서 귀하의 연령은 일종의 숫자가 아닌 직원 유형입니다. 심지어 a < age이 컴파일되어야할지 확신하지 못합니다.

어떤 일이 일어나고 있는지 직원이 int로 나눌 수 있는지 알아 내려고 시도하고 있습니다. PrimeAgeChecker에있는 당신의 나이는 int로 정의되어야하고()

+0

안녕 조모 PrimeAgeChecker pac=new PrimeAgeChecker();pac.check(); 그런 짓을? 감사합니다. –

+0

employee.getAge() 여기서 employee는 Employee 유형의 객체입니다. – JoMo

0

당신은 아무것도 생략하지 않은 것으로 가정 employee.getAge를 사용하여 설정할 수, 당신은 방법 check()을 연상 결코 checkcheck()와 동일하지 않습니다. 실제로 PrimeAgeChecker 인스턴스가 없습니다.

어느

는 당신은 어떻게 PrimeAgeCheck에서 직원의 나이를 얻는 말해 줄 수, PrimeAgeCheckerstatic 수정을 추가하고 PrimeAgeChecker.check(), 전화를 걸거나

관련 문제