-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSektori.java
81 lines (67 loc) · 1.57 KB
/
Sektori.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
public class Sektori {
private Nappula[] nappulat;
private int moneskoMerkki;
public Sektori(Nappula[] nappulat1, int koko) {
nappulat = new Nappula[koko];
for (int i = 0; i < nappulat1.length; i++) {
nappulat[i] = nappulat1[i];
}
}
public Sektori(int koko) {
nappulat = new Nappula[koko];
}
public int kerroNappulat() {
int nappulat = 0;
for(int i = 0; i < this.nappulat.length; i++) {
if (this.nappulat[i] != null)
nappulat++;
}
return nappulat;
}
public Nappula[] kerroNappulaTaulukko() {
return this.nappulat;
}
public Nappula kerroNappula() {
int apuindeksi;
if (this.kerroNappulat() == 0) {
return null;
}
else {
apuindeksi = this.kerroNappulat() - 1;
}
return nappulat[apuindeksi];
}
public String toString() {
String esitys = "";
for(int i=0;i<this.kerroNappulat();i++) {
if(nappulat[i].kerroVari() == 0) {
esitys = esitys + "0";
}
if(nappulat[i].kerroVari() == 1) {
esitys = esitys + "1";
}
}
return esitys;
}
public Nappula poistaNappula() {
int apuindeksi;
if (this.kerroNappulat() == 0) {
return null;
}
else {
apuindeksi = this.kerroNappulat() - 1;
}
Nappula apunappula = this.nappulat[apuindeksi];
this.nappulat[apuindeksi] = null;
return apunappula;
}
public boolean lisaaNappula (Nappula nappula, int sektori) {
if (this.kerroNappulat() == this.nappulat.length)
return false;
else {
this.nappulat[this.kerroNappulat()] = nappula;
this.kerroNappula().asetaSijainti(sektori);
return true;
}
}
}