-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
executable file
·83 lines (77 loc) · 2.36 KB
/
Copy pathPerson.java
File metadata and controls
executable file
·83 lines (77 loc) · 2.36 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
* Person represents the important aspects of a person according to
* Carroll's logic puzzle
*
* @author ace
* @version 11 April 2010
*/
public class Person
{
// instance variables - replace the example below with your own
private boolean isBaby;
private boolean canManageCrocodile;
private boolean isLogical;
/**
* Constructor for objects of class Person
*/
public Person(boolean isBaby, boolean canManageCrocodile, boolean isLogical){
this.isBaby = isBaby;
this.canManageCrocodile = canManageCrocodile;
this.isLogical = isLogical;
consistencyCheck();
}
/**
* Carroll tells us that no one is despised who can manage a crocodile,
* and no babies are logical. Therefore we must correct for the following
* impossible combinations:
* isBaby + isLogical
* isBaby + canManageCrocodile
* !isLogical + canManageCrocodile
*/
private void consistencyCheck(){
if(isBaby && isLogical){
//this is not possible, so we must decide if this Person
//is not a baby or is not logical.
//if they can manage a crocodile, then 2/3 says they are logical -
//therefore not a baby.
if(canManageCrocodile){
isBaby = false;
} else {
isLogical = false;
}
}
if(isBaby && canManageCrocodile){
//again, we check to see if the person is logical, since no
//one who can manage a crocodile is illogical.
if(!isLogical){
canManageCrocodile = false;
} //isBaby && isLogical && canManageCrocodile is dealt with above
}
if(!isLogical && canManageCrocodile){
if(!isBaby){
isLogical = true;
} //the other possibilities have already been dealt with above
}
}
/**
* Returns true if this Person is a Baby
* @return boolean
*/
public boolean isBaby(){
return isBaby;
}
/**
* Returns true if this Person can manage a crocodile
* @return boolean
*/
public boolean canManageCrocodile(){
return canManageCrocodile;
}
/**
* Returns true if this Person is a Logical
* @return boolean
*/
public boolean isLogical(){
return isLogical;
}
}