Upload files to "source"
This commit is contained in:
52
source/Field.java
Normal file
52
source/Field.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package serie04;
|
||||
|
||||
public class Field {
|
||||
|
||||
private int size;
|
||||
private Addition addition;
|
||||
private Multiplication multiplication;
|
||||
|
||||
public Field(int size, Addition addition, Multiplication multiplication) {
|
||||
|
||||
if(addition.getSize() != size || multiplication.getSize() + 1 != size) {
|
||||
throw new ArithmeticException();
|
||||
}
|
||||
|
||||
this.size = size;
|
||||
this.addition = addition;
|
||||
this.multiplication = multiplication;
|
||||
}
|
||||
|
||||
public boolean checkDistributivity(int indexA, int indexB, int indexC) {
|
||||
|
||||
int leftSide = multiplication.calculate(indexA, addition.calculate(indexB, indexC));
|
||||
int rightSide = addition.calculate(multiplication.calculate(indexA, indexB), multiplication.calculate(indexA, indexC));
|
||||
|
||||
return leftSide == rightSide;
|
||||
}
|
||||
|
||||
public boolean checkDistributivity() {
|
||||
|
||||
for(int a = 0; a < this.size; a++) {
|
||||
for(int b = 0; b < this.size; b++) {
|
||||
for(int c = 0; c < this.size; c++) {
|
||||
if (this.checkDistributivity(a, b, c) == false) return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean verifyField() {
|
||||
|
||||
if (this.multiplication.validateTable() == false) return false;
|
||||
|
||||
if (this.addition.validateTable() == false) return false;
|
||||
|
||||
if (this.checkDistributivity() == false) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user