-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOperations.java
104 lines (97 loc) · 3.32 KB
/
Operations.java
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
public class Operations{
public static Proposition Negate(Proposition x){
for (int index = 0; index < 4; index++) {
if (x.getValue(index)) {
x.setValue(index, false);
} else {
x.setValue(index, true);
}
}
return x;
}
public static Proposition Conjunction(Proposition x, Proposition y){
Prop_0 and_answer = new Prop_0();
for (int index = 0; index < 4; index++) {
if (x.getValue(index) && y.getValue(index)) {
and_answer.setValue(index, true);
} else {
and_answer.setValue(index, false);
}
}
return and_answer;
}
public static Proposition Disjunction(Proposition x, Proposition y){
Prop_0 or_answer = new Prop_0();
for (int index = 0; index < 4; index++) {
if (x.getValue(index) || y.getValue(index)) {
or_answer.setValue(index, true);
} else {
or_answer.setValue(index, false);
}
}
return or_answer;
}
public static Proposition Conditional(Proposition x, Proposition y){
Prop_0 then_answer = new Prop_0();
for (int index = 0; index < 4; index++) {
if (x.getValue(index)){
if(!y.getValue(index)){
then_answer.setValue(index, false);
}
else{
then_answer.setValue(index, true);
}
}
else{
then_answer.setValue(index, true);
}
}
return then_answer;
}
public static Proposition Biconditional(Proposition x, Proposition y){
Prop_0 if_then_answer = new Prop_0();
for(int index = 0; index < 4; index++){
if(x.getValue(index) == y.getValue(index)){
if_then_answer.setValue(index, true);
}
else{
if_then_answer.setValue(index, false);
}
}
return if_then_answer;
}
public static Proposition NAND(Proposition x, Proposition y){
Prop_0 NAND_answer = new Prop_0();
for (int index = 0; index < 4; index++) {
if (x.getValue(index) && y.getValue(index)) {
NAND_answer.setValue(index, false);
} else {
NAND_answer.setValue(index, true);
}
}
return NAND_answer;
}
public static Proposition NOR(Proposition x, Proposition y){
Prop_0 NOR_answer = new Prop_0();
for (int index = 0; index < 4; index++) {
if (x.getValue(index) || y.getValue(index)) {
NOR_answer.setValue(index, false);
} else {
NOR_answer.setValue(index, true);
}
}
return NOR_answer;
}
public static Proposition XOR(Proposition x, Proposition y){
Prop_0 XOR_answer = new Prop_0();
for(int index = 0; index < 4; index++){
if(x.getValue(index) == y.getValue(index)){
XOR_answer.setValue(index, false);
}
else{
XOR_answer.setValue(index, true);
}
}
return XOR_answer;
}
}