Adding day 1 and day 3 of OOP2 to the project. Because of a typo, the server was rebooted, so other days will be added later.
- Author
- Maarten Vangeneugden
- Date
- Nov. 13, 2015, 11:30 a.m.
- Hash
- ec784ef46729d6aa39254d243bd10d18625e1fad
- Parents
- Modified files
- 01/OEF01.java
- 01/OEF02.java
- 01/OEF03.java
- 01/OEF04.java
- 01/OEF05.java
- 01/OEF06.java
- 03/Artikel.java
- 03/ArtikelIO.java
- 03/AudioCD.java
- 03/Boek.java
- 03/Stripboek.java
- 03/Winkel.java
- 03/WinkelKar.java
01/OEF01.java ¶
9 additions and 0 deletions.
01/OEF02.java ¶
25 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
+ |
3 |
you may not use this file except in compliance with the License. |
+ |
4 |
You may obtain a copy of the License at |
+ |
5 |
|
+ |
6 |
https://www.apache.org/licenses/LICENSE-2.0 |
+ |
7 |
|
+ |
8 |
Unless required by applicable law or agreed to in writing, software |
+ |
9 |
distributed under the License is distributed on an "AS IS" BASIS, |
+ |
10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+ |
11 |
See the License for the specific language governing permissions and |
+ |
12 |
limitations under the License.*/ |
+ |
13 |
import java.util.*; |
+ |
14 |
|
+ |
15 |
class OEF02 |
+ |
16 |
{ |
+ |
17 |
public static void main(String[] args) |
+ |
18 |
{ |
+ |
19 |
for(int i=0; i<args.length && i<3; i++) |
+ |
20 |
{ |
+ |
21 |
System.out.println(args[i]); |
+ |
22 |
} |
+ |
23 |
} |
+ |
24 |
} |
+ |
25 |
01/OEF03.java ¶
46 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
+ |
3 |
you may not use this file except in compliance with the License. |
+ |
4 |
You may obtain a copy of the License at |
+ |
5 |
|
+ |
6 |
https://www.apache.org/licenses/LICENSE-2.0 |
+ |
7 |
|
+ |
8 |
Unless required by applicable law or agreed to in writing, software |
+ |
9 |
distributed under the License is distributed on an "AS IS" BASIS, |
+ |
10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+ |
11 |
See the License for the specific language governing permissions and |
+ |
12 |
limitations under the License.*/ |
+ |
13 |
import java.util.*; |
+ |
14 |
|
+ |
15 |
class Matrix |
+ |
16 |
{ |
+ |
17 |
//No constructor. Java makes a default constructor. |
+ |
18 |
|
+ |
19 |
public int[][] matrix() |
+ |
20 |
{ |
+ |
21 |
return m_matrix; |
+ |
22 |
} |
+ |
23 |
public void setMatrix(int[][] matrix) |
+ |
24 |
{ |
+ |
25 |
for(int i=0; i<3; i++) |
+ |
26 |
for(int j=0; j<3; j++) |
+ |
27 |
m_matrix[i][j] = matrix[i][j]; |
+ |
28 |
} |
+ |
29 |
|
+ |
30 |
public void sum(Matrix matrix) |
+ |
31 |
{ |
+ |
32 |
for(int i=0; i<3; i++) |
+ |
33 |
for(int j=0; j<3; j++) |
+ |
34 |
m_matrix[i][j] += matrix.matrix()[i][j]; |
+ |
35 |
} |
+ |
36 |
|
+ |
37 |
public void product(Matrix matrix) |
+ |
38 |
{ |
+ |
39 |
for(int i=0; i<3; i++) |
+ |
40 |
for(int j=0; j<3; j++) |
+ |
41 |
m_matrix[i][j] *= matrix.matrix()[i][j]; |
+ |
42 |
} |
+ |
43 |
|
+ |
44 |
private int m_matrix[][]; |
+ |
45 |
} |
+ |
46 |
01/OEF04.java ¶
35 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
+ |
3 |
you may not use this file except in compliance with the License. |
+ |
4 |
You may obtain a copy of the License at |
+ |
5 |
|
+ |
6 |
https://www.apache.org/licenses/LICENSE-2.0 |
+ |
7 |
|
+ |
8 |
Unless required by applicable law or agreed to in writing, software |
+ |
9 |
distributed under the License is distributed on an "AS IS" BASIS, |
+ |
10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+ |
11 |
See the License for the specific language governing permissions and |
+ |
12 |
limitations under the License.*/ |
+ |
13 |
import java.util.*; |
+ |
14 |
|
+ |
15 |
class OEF04 |
+ |
16 |
{ |
+ |
17 |
public static void main(String[] args) |
+ |
18 |
{ |
+ |
19 |
Random random = new Random(); |
+ |
20 |
for(int i=0; i<25; i++) |
+ |
21 |
{ |
+ |
22 |
int a = random.nextInt(); |
+ |
23 |
int b = random.nextInt(); |
+ |
24 |
System.out.print(a + " is "); |
+ |
25 |
if(a>b) |
+ |
26 |
System.out.print("groter dan"); |
+ |
27 |
else if(a==b) |
+ |
28 |
System.out.print("gelijk aan"); |
+ |
29 |
else |
+ |
30 |
System.out.print("kleiner dan"); |
+ |
31 |
System.out.println(" " + b); |
+ |
32 |
} |
+ |
33 |
} |
+ |
34 |
} |
+ |
35 |
01/OEF05.java ¶
33 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
+ |
3 |
you may not use this file except in compliance with the License. |
+ |
4 |
You may obtain a copy of the License at |
+ |
5 |
|
+ |
6 |
https://www.apache.org/licenses/LICENSE-2.0 |
+ |
7 |
|
+ |
8 |
Unless required by applicable law or agreed to in writing, software |
+ |
9 |
distributed under the License is distributed on an "AS IS" BASIS, |
+ |
10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+ |
11 |
See the License for the specific language governing permissions and |
+ |
12 |
limitations under the License.*/ |
+ |
13 |
import java.util.*; |
+ |
14 |
|
+ |
15 |
class OEF05 |
+ |
16 |
{ |
+ |
17 |
public static void main(String[] args) |
+ |
18 |
{ |
+ |
19 |
System.out.println("Priemgetallen t.e.m. " + args[0] + ":"); |
+ |
20 |
for(int i=2; i<Integer.parseInt(args[0])+1; i++) |
+ |
21 |
{ |
+ |
22 |
boolean priem = true; |
+ |
23 |
for(int j=2; j<i; j++) |
+ |
24 |
{ |
+ |
25 |
if(i%j == 0) |
+ |
26 |
priem = false; |
+ |
27 |
} |
+ |
28 |
if(priem) |
+ |
29 |
System.out.println(i); |
+ |
30 |
} |
+ |
31 |
} |
+ |
32 |
} |
+ |
33 |
01/OEF06.java ¶
56 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
Licensed under the Apache License, Version 2.0 (the "License"); |
+ |
3 |
you may not use this file except in compliance with the License. |
+ |
4 |
You may obtain a copy of the License at |
+ |
5 |
|
+ |
6 |
https://www.apache.org/licenses/LICENSE-2.0 |
+ |
7 |
|
+ |
8 |
Unless required by applicable law or agreed to in writing, software |
+ |
9 |
distributed under the License is distributed on an "AS IS" BASIS, |
+ |
10 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
+ |
11 |
See the License for the specific language governing permissions and |
+ |
12 |
limitations under the License.*/ |
+ |
13 |
import java.util.*; |
+ |
14 |
public class Person |
+ |
15 |
{ |
+ |
16 |
Person(){} |
+ |
17 |
Person(String voornaam, String naam, char geslacht) |
+ |
18 |
{ |
+ |
19 |
setVoornaam(voornaam); |
+ |
20 |
setNaam(naam); |
+ |
21 |
setGeslacht(geslacht); |
+ |
22 |
} |
+ |
23 |
|
+ |
24 |
public boolean equals(Person p) //OEF06.2 |
+ |
25 |
{ |
+ |
26 |
return (m_voornaam == p.voornaam() && |
+ |
27 |
m_naam == p.naam() && |
+ |
28 |
m_geslacht == p.geslacht()); |
+ |
29 |
//Het verschil met een simpele "==" tussen 2 objecten, is dat hier wordt gekeken of de waarden overeenstemmen. Bij een "==" tussen objecten moeten beide objecten gelijk zijn. |
+ |
30 |
} |
+ |
31 |
|
+ |
32 |
public String voornaam() |
+ |
33 |
return m_voornaam; |
+ |
34 |
public void setVoornaam(String voornaam) |
+ |
35 |
m_voornaam = voornaam; |
+ |
36 |
|
+ |
37 |
public String naam() |
+ |
38 |
return m_naam; |
+ |
39 |
public void setNaam(String naam) |
+ |
40 |
m_naam = naam; |
+ |
41 |
|
+ |
42 |
public char geslacht() |
+ |
43 |
return m_geslacht; |
+ |
44 |
public void setGeslacht(String geslacht) |
+ |
45 |
m_geslacht = geslacht; |
+ |
46 |
|
+ |
47 |
private String m_voornaam; |
+ |
48 |
private String m_naam; |
+ |
49 |
private char m_geslacht; |
+ |
50 |
|
+ |
51 |
//OEF06.3 |
+ |
52 |
private Person partner; |
+ |
53 |
private Person mom; |
+ |
54 |
private Person dad; |
+ |
55 |
} |
+ |
56 |
03/Artikel.java ¶
22 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
abstract class Artikel |
+ |
3 |
{ |
+ |
4 |
private int m_prijs; |
+ |
5 |
private String m_naam; |
+ |
6 |
public int prijs(){ |
+ |
7 |
return m_prijs;} |
+ |
8 |
public void setPrijs(int prijs){ |
+ |
9 |
m_prijs = prijs;} |
+ |
10 |
public String naam(){ |
+ |
11 |
return m_naam;} |
+ |
12 |
public void setNaam(String naam){ |
+ |
13 |
m_naam = naam;} |
+ |
14 |
|
+ |
15 |
abstract void toon(); |
+ |
16 |
abstract String geefType(); //Returned de naam van het type van deze class. |
+ |
17 |
} |
+ |
18 |
//Antwoord op de vraag: Is het nog nodig dat we een geefType() method voorzien om, afhankelijk van het type object specifieke functionaliteit uit te voeren? |
+ |
19 |
//Neen. Als we ervan uitgaan dat de type objecten correct inheritance toepassen, dan kunnen we erop vertrouwen dat diezelfde objecten hun functionaliteit sowieso correct zullen uitvoeren. We hoeven dan niet te controleren op het type object. |
+ |
20 |
//Antwoord op de vraag: Wat zijn de nadelen van met een geefType() method te werken? |
+ |
21 |
//Ten eerste voegen dergelijke functies onnodige boilerplatecode toe aan de classes. Er moet voor elke classe die van Artikel inherit extra code worden toegevoegd om iets aan te geven wat, als de inheritance goed is, triviaal en onnodig is. Ook zijn dergelijke functies in strijd met het GRASP-principe "High cohesion/Low coupling", en (voor discussie vatbaar) vermindert de herbruikbaarheid van de code. |
+ |
22 |
03/ArtikelIO.java ¶
28 additions and 0 deletions.
View changes Hide changes
+ |
1 |
import java.io.*; |
+ |
2 |
|
+ |
3 |
class ArtikelIO |
+ |
4 |
{ |
+ |
5 |
public ArtikelIO(Artikel artikel) |
+ |
6 |
{ |
+ |
7 |
setArtikel(artikel); |
+ |
8 |
} |
+ |
9 |
public ArtikelIO(LinkedList<Artikel> artikelen) |
+ |
10 |
{ |
+ |
11 |
setArtikelen(artikelen); |
+ |
12 |
} |
+ |
13 |
public ArtikelIO(); |
+ |
14 |
|
+ |
15 |
private LinkedList<Artikel> a_artikelen; |
+ |
16 |
private Artikel m_artikel; |
+ |
17 |
|
+ |
18 |
public LinkedList<Artikel> artikelen() |
+ |
19 |
return a_artikelen; |
+ |
20 |
public void setArtikelen(LinkedList<Artikel> artikelen) |
+ |
21 |
a_artikelen = artikelen; |
+ |
22 |
|
+ |
23 |
public Artikel artikel() |
+ |
24 |
return m_artikel; |
+ |
25 |
public void setArtikel() |
+ |
26 |
m_artikel = artikel; |
+ |
27 |
//Moet nog worden afgewerkt. |
+ |
28 |
03/AudioCD.java ¶
24 additions and 0 deletions.
View changes Hide changes
+ |
1 |
{ |
+ |
2 |
private int m_tracks; |
+ |
3 |
private String m_artiest; |
+ |
4 |
public int tracks(){ |
+ |
5 |
return m_tracks;} |
+ |
6 |
public void setTracks(int tracks){ |
+ |
7 |
m_tracks = tracks;} |
+ |
8 |
public String artiest(){ |
+ |
9 |
return m_artiest;} |
+ |
10 |
public void setArtiest(String artiest){ |
+ |
11 |
m_artiest = artiest;} |
+ |
12 |
|
+ |
13 |
public void toon() |
+ |
14 |
{ |
+ |
15 |
System.out.println("Tracks: " + tracks()); |
+ |
16 |
System.out.println("Artiest: " + artiest()); |
+ |
17 |
} |
+ |
18 |
|
+ |
19 |
public String geefType() |
+ |
20 |
{ |
+ |
21 |
return "AudioCD"; |
+ |
22 |
} |
+ |
23 |
} |
+ |
24 |
03/Boek.java ¶
24 additions and 0 deletions.
View changes Hide changes
+ |
1 |
{ |
+ |
2 |
private int m_ISBN; |
+ |
3 |
private String m_auteur; |
+ |
4 |
public int ISBN(){ |
+ |
5 |
return m_ISBN;} |
+ |
6 |
public void setISBN(int ISBN){ |
+ |
7 |
m_ISBN = ISBN;} |
+ |
8 |
public String auteur(){ |
+ |
9 |
return m_auteur;} |
+ |
10 |
public void setAuteur(String auteur){ |
+ |
11 |
m_auteur = auteur;} |
+ |
12 |
|
+ |
13 |
public void toon() |
+ |
14 |
{ |
+ |
15 |
System.out.println("ISBN: " + ISBN()); |
+ |
16 |
System.out.println("Auteur: " + auteur()); |
+ |
17 |
} |
+ |
18 |
|
+ |
19 |
public String geefType() |
+ |
20 |
{ |
+ |
21 |
return "Boek"; |
+ |
22 |
} |
+ |
23 |
} |
+ |
24 |
03/Stripboek.java ¶
23 additions and 0 deletions.
View changes Hide changes
+ |
1 |
{ |
+ |
2 |
private int m_reeksnummer; |
+ |
3 |
private String m_reeksnaam; |
+ |
4 |
public int reeksnummer(){ |
+ |
5 |
return m_reeksnummer;} |
+ |
6 |
public void setReeksnummer(int reeksnummer){ |
+ |
7 |
m_reeksnummer = reeksnummer;} |
+ |
8 |
public String reeksnaam(){ |
+ |
9 |
return m_reeksnaam;} |
+ |
10 |
public void setReeksnaam(String reeksnaam){ |
+ |
11 |
m_reeksnaam = reeksnaam;} |
+ |
12 |
|
+ |
13 |
public void toon() |
+ |
14 |
{ |
+ |
15 |
System.out.println("Reeksnummer: " + reeksnummer()); |
+ |
16 |
System.out.println("Reeksnaam: " + reeksnaam()); |
+ |
17 |
} |
+ |
18 |
public String geefType() |
+ |
19 |
{ |
+ |
20 |
return "Stripboek"; |
+ |
21 |
} |
+ |
22 |
} |
+ |
23 |
03/Winkel.java ¶
28 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
class Winkel |
+ |
3 |
{ |
+ |
4 |
private LinkedList<Artikel> a_artikelen; |
+ |
5 |
public LinkedList<Artikel> artikelen(){ |
+ |
6 |
return a_artikelen;} |
+ |
7 |
public void setArtikelen(LinkedList<Artikel> artikelen) |
+ |
8 |
{ |
+ |
9 |
a_artikelen = artikelen; |
+ |
10 |
} |
+ |
11 |
public void toonArtikelen(){ |
+ |
12 |
for(int i=0; i<artikelen().size(); i++){ |
+ |
13 |
artikelen().get(i).toon(); |
+ |
14 |
System.out.println("------------------"); |
+ |
15 |
} |
+ |
16 |
} |
+ |
17 |
|
+ |
18 |
public void add(Artikel artikel) |
+ |
19 |
{ |
+ |
20 |
a_artikelen.add(artikel); |
+ |
21 |
} |
+ |
22 |
|
+ |
23 |
public void remove(int index) |
+ |
24 |
{ |
+ |
25 |
a_artikelen.remove(index); |
+ |
26 |
} |
+ |
27 |
} |
+ |
28 |
03/WinkelKar.java ¶
40 additions and 0 deletions.
View changes Hide changes
+ |
1 |
|
+ |
2 |
class Winkelkar |
+ |
3 |
{ |
+ |
4 |
|
+ |
5 |
private LinkedList<Artikel> a_artikelen; |
+ |
6 |
public LinkedList<Artikel> artikelen(){ |
+ |
7 |
return a_artikelen;} |
+ |
8 |
public void setArtikelen(LinkedList<Artikel> artikelen) |
+ |
9 |
{ |
+ |
10 |
a_artikelen = artikelen; |
+ |
11 |
} |
+ |
12 |
|
+ |
13 |
public void totaalprijs() |
+ |
14 |
{ |
+ |
15 |
int totaal=0; |
+ |
16 |
for(int i=0; i<artikelen().size(); i++) |
+ |
17 |
{ |
+ |
18 |
totaal += artikelen().get(i).prijs(); |
+ |
19 |
} |
+ |
20 |
System.out.println("Totaalprijs: " + totaal); |
+ |
21 |
} |
+ |
22 |
|
+ |
23 |
public void toonArtikelen(){ |
+ |
24 |
for(int i=0; i<artikelen().size(); i++){ |
+ |
25 |
artikelen().get(i).toon(); |
+ |
26 |
System.out.println("------------------"); |
+ |
27 |
} |
+ |
28 |
} |
+ |
29 |
|
+ |
30 |
public void add(Artikel artikel) |
+ |
31 |
{ |
+ |
32 |
a_artikelen.add(artikel); |
+ |
33 |
} |
+ |
34 |
|
+ |
35 |
public void remove(int index) |
+ |
36 |
{ |
+ |
37 |
a_artikelen.remove(index); |
+ |
38 |
} |
+ |
39 |
} |
+ |
40 |