I have to create an object array, but I can't figure out why it is instantiating to null every time. The class' constructor is not empty, it has 2 parameters, so I can't initialize it with new Share()
.
public class Portfolio {
private Share[] share;
private int noShares = 0;
public Portfolio() {} //constructor
public void addShare(Share s) {
share[noShares++] = new Share(s.getValue(), s.getCompany());
}
I have also tried this, but it gives the same error
share[noShares].setValue(s.getValue));
share[noShares++].setCompany(s.getCompany);
And this is the last method
public double computeSum() {
int sum = 0;
for(int i = 0; i < noShares; i++) {
sum += share[noShares].getValue();
}
return sum;
}
}