ik ben bezig met een schooltaak
als ik mijn classes wil runne krijg ik een null pointer exeption
in de methode addHousehold (staat vet gedrukt)
wie kan mij zeggen wat ik fout doe en hoe ik mijn fout kan herstellen?
hieronder de code
alvast bedankt
als ik mijn classes wil runne krijg ik een null pointer exeption
in de methode addHousehold (staat vet gedrukt)
wie kan mij zeggen wat ik fout doe en hoe ik mijn fout kan herstellen?
hieronder de code
alvast bedankt
code:
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
| package households;
public class Household {
// Variabelen
protected String name;
protected int householdID;
protected int members;
protected double income;
// Constructors
public Household (){
}
public Household (int householdID, int members, double income) {
super();
this.householdID = householdID;
this.members = members;
this.income = income;
}
// Getters
public int getHouseholdID() {
return householdID;
}
public double getIncome() {
return income;
}
public int getMembers() {
return members;
}
public String getName() {
return name;
}
// Setters
public void setHouseholdID(int householdID) {
this.householdID = householdID;
}
public void setIncome(double income) {
this.income = income;
}
public void setMembers(int members) {
this.members = members;
}
public void setName(String name) {
this.name = name;
}
// Methoden
public String poveryLevel (){
if (income <= (6500.00 + (750.00 * (members -2)))){
System.out.println((6500.00 + (750.00 * (members -2))));
return ("Its a household below the povery level");
}
System.out.println((6500.00 + (750.00 * (members -2))));
return ("it's a household above the povery level");
}
}
package households;
import java.util.*;
public class Township {
// Variabelen
protected HashSet households;
//protected double averageIncome ;
// Constructors
public Township (){
}
public Township (HashSet households){
this.households = new HashSet();
//this.averageIncome = averageIncome;
}
// Getters
public double getAverageIncome() {
double t = 0.0;
Iterator incomeIterator = households.iterator();
while (incomeIterator.hasNext()){
t += ((Household)incomeIterator.next()).getIncome();
}
return t;
}
public HashSet getHouseholds() {
return households;
}
// Setters
/*
public void setAverageIncome(double averageIncome) {
this.averageIncome = averageIncome;
}
public void setHouseholds(HashSet households) {
this.households = households;
}
public void setTownshipName() {
}
*/
// Methoden
// hier moet een iterator over de collectie lopen
public double average (){
return 0.0;
}
[b] public void addHousehold (Household household){
this.households.add(household);
}[/b]
public int countHouseholds (){
return this.households.size();
}
package testHouseholds;
import households.*;
import junit.framework.TestCase;
public class TestHousehold extends TestCase {
// Variabelen
private Township Lokeren = new Township ();
private Household VanDamme = new Household (0001, 4, 70000.00);
private Household VanDeWalle = new Household (0002, 2, 76000.00);
private Household Impens = new Household (0003, 5, 110000.00);
private Household DeSmet = new Household (0004, 4, 930000.00);
private Household Lambert = new Household (0005, 5, 80000.00);
// Constructors
public TestHousehold (String name){
super(name);
}
protected void Setup () throws Exception{
super.setUp();
}
public void testHouseholds (){
assertEquals ("nummer van familie VanDamme", 0001, this.VanDamme.getHouseholdID());
assertEquals ("aantal gezinsleden bij VanDamme", 4, this.VanDamme.getMembers());
assertEquals ("inkomen bij VanDamme", 70000.00, this.VanDamme.getIncome(), 0.0);
Lokeren.addHousehold(VanDamme);
//assertEquals ("Families in de gemeente",1, this.Lokeren.countHouseholds() );
//assertEquals ("financiele toestand", "Its a household above the povery level", this.VanDamme.poveryLevel());
//assertEquals ("Families in de gemeente",2, this.Lokeren.countHouseholds() );
/*
this.Lokeren.addHousehold(Impens);
assertEquals ("Families in de gemeente",3, this.Lokeren.countHouseholds() );
this.Lokeren.addHousehold(DeSmet);
assertEquals ("Families in de gemeente",4, this.Lokeren.countHouseholds() );
this.Lokeren.addHousehold(Lambert);
assertEquals ("Families in de gemeente",5, this.Lokeren.countHouseholds());
//assertEquals ("Gemiddlede inkomen", 70000.00, this.Lokeren.getAverageIncome(), 0.0);
*/
}
}
} |