non static method problem
non static method getpris cannot be referenced from a static contexther er klassen der giver fejlen
import java.util.*;
public class PurchaseStack extends java.util.Vector {
private double total;
private int c;
public PurchaseStack() {
c = 0;
}
public void push(Vare in) {
//true
//post: in attached to container
add(in);
}
public double purchaseSum() {
//true
//post: return Sum of total[0..c[
double b = 0;
int i;
Iterator it = iterator();
while(it.hasNext()) {
VareImpl tmp = (VareImpl)it.next();
b = b + VareImpl.getPris();
}
return b;
}
}
den bruger denne klasse
/*
* forfatter: Ole Bloch
* forklaring: abstrakt klasse vare
* lavet: 17.02.2002
*
*
*/
public class VareImpl implements VareSystemKrav {
protected double pris;
protected double moms;
protected String vareNr;
//konstruktør
public VareImpl(double p) {
//pre: p > 0 && moms is a natural number
//post: True
this.pris = p;
//set moms to 30 %
this.moms = 30.0;
this.moms = this.moms / 100;
}//end constructor
public double getPris() {
return this.pris;
}
}//end Vare
Hvad er der at gøre ved det
