Testeksamne, og andre ting
This commit is contained in:
70
Testeksamen/Example.java
Normal file
70
Testeksamen/Example.java
Normal file
@@ -0,0 +1,70 @@
|
||||
public class Example {
|
||||
public static void main(String[] args) {
|
||||
boolean m[][] = { { true, false, true, true },
|
||||
{ true, false, true, false },
|
||||
{ true, false, true, true } };
|
||||
System.out.println("++++++++++++");
|
||||
Grid g = new Grid(m);
|
||||
System.out.println(g);
|
||||
System.out.println("++++++++++++");
|
||||
g.update();
|
||||
System.out.println(g);
|
||||
System.out.println("++++++++++++");
|
||||
}
|
||||
}
|
||||
|
||||
public class Data {
|
||||
private int major;
|
||||
private int minor;
|
||||
private boolean active;
|
||||
public Data(int major, int minor, boolean active) {
|
||||
this.major = Math.max(0, major);
|
||||
this.minor = Math.max(0, minor);
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public int getMajor() {
|
||||
return this.major;
|
||||
}
|
||||
public int getMinor() {
|
||||
return this.minor;
|
||||
}
|
||||
public boolean getActive() {
|
||||
return this.active;
|
||||
}
|
||||
public void parity() {
|
||||
this.major = this.major % 2;
|
||||
this.minor = this.minor % 2;
|
||||
}
|
||||
public String toString() {
|
||||
return "" + this.major + (this.active ? "**" : "//") + this.minor;
|
||||
}
|
||||
}
|
||||
|
||||
public class Grid {
|
||||
private Data[] a;
|
||||
public Grid(boolean[][] m) {
|
||||
this.a = new Data[m[0].length * m.length];
|
||||
for (int i = 0; i < m.length; i++) {
|
||||
for (int j = 0; j < m[i].length; j++) {
|
||||
this.a[(m[0].length * i)+j] = new Data(i, j, m[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void update() {
|
||||
for (int i = 0; i < this.a.length; i++) {
|
||||
if (this.a[i].getActive()) {
|
||||
this.a[i].parity();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String return_string = "";
|
||||
for (int i = 0; i < this.a.length; i++) {
|
||||
return_string += this.a[i] + (i == this.a.length - 1 ? "" : "-");
|
||||
}
|
||||
return return_string;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user