Upload files to "source"

This commit is contained in:
2025-10-22 16:51:27 +00:00
parent 5126aada7c
commit bc614f1a03
5 changed files with 197 additions and 0 deletions

52
source/Field.java Normal file
View 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;
}
}