728x90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package sample;
 
public class Exam06_5_Human {
    char type;
    String name;
    int age;
    
    
    public char getType() {
        return type;
    }
    public void setType(char type) {
        this.type = type;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
    
    
    /* setter, getter 메소드 작성 */
}
 
cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package sample;
 
public class Exam06_5_Main {
    public static void main(String[] args) {
        /* 헌혈자 정보 */
        Exam06_5_Human human = new Exam06_5_Human();
        human.setName("김");
        human.setType('O');
        human.setAge(25);
 
        /* BloodHouse 객체 생성 */
        Exam06_5_BloodHouse bh = new Exam06_5_BloodHouse();
        String result = bh.action(human);
        
        //isPossible() 파라미터로 뭐가 들어갈지를 모르고있네..
        //Human human의 정체를 모르고 있네..
        
        /* action() 메소드를 호출하면서 매개변수로 헌혈자 정보 넘겨줌 */
        /* action() 메소드 호출 결과 출력 */
        System.out.println(result);
    }
}
cs

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package sample;
 
public class Exam06_5_BloodHouse {
    public boolean isPossible(Exam06_5_Human human) {
        int age = 0// 헌혈자의 나이를 확인하여 저장
        boolean isPossible = false// 헌혈 가능 여부
        /* 넘겨받은 Human 클래스로부터 age 정보 확인 age = ? */
        age = human.getAge();
        
        
        /* age가 16세 이상 69세 이하 일때만 헌혈 가능하도록 조건문 작성 */
        if(human.age>= 16 &&  human.age<= 69) {
            isPossible = true;
        }
        return isPossible;
    }
 
    public String action(Exam06_5_Human human) {
        boolean res = isPossible(human);
        String result = ""// 헌혈 결과 저장
        /* isPossible() 메소드를 활용하여 헌혈 가능 여부를 확인하는 조건문 작성 */
        if(res == true) {
            result = "헌혈이 완료되었습니다. XX님 감사합니다.";
        } else {
            result = "헌혈이 불가능합니다.";
        }
        /* 헌혈 가능 시 result = "헌혈이 완료되었습니다. XX님 감사합니다. */
        /* 헌혈 불가 시 result = "헌혈이 불가능합니다. */
        return result;
    }
}
cs

 

'Java' 카테고리의 다른 글

[스프링] JPA  (0) 2020.06.24
[Java] Teachable MachineLearning with Google.  (0) 2020.06.19
[Java] JSON형식 Parsing  (0) 2020.06.09
[Java] hosts파일  (0) 2020.06.05
[자바] 2020-06-03  (0) 2020.06.03

+ Recent posts