Hallo,
ich habe eine Aufgabe, so geschrieben :
FondInvestment: Auch in der FondInvestment-Klasse soll das Stock-Objekt mit dem Share Objekt ausgetauscht werden. Legen sie im FondInvestment zusätzlich einen neuen Konstruktor an, der eine Sammlung von Shares übergeben bekommt und den Fond-Preis aus der Summe der übergebenen Shares berechnet.
Nach dem Abschluss dieser Änderung soll die FondInvestment-Klasse folgende Methoden haben:
public FondInvestment(Share ... shares)
public FondInvestment(double price, Share ... shares)
public double netAssetValue() public double absolutePriceDelta()
public String toString()
public double projectedEarningsPerYear()
Was ich nicht verstanden habe ist diese Aussage " Legen sie im FondInvestment zusätzlich einen neuen Konstruktor an, der eine Sammlung von Shares übergeben bekommt und den Fond-Preis aus der Summe der übergebenen Shares berechnet. "
Ich habe 2 Konstruktoren mit gleichem Namen in einer Klasse. Also habe ich so geschrieben :
ich habe eine Aufgabe, so geschrieben :
FondInvestment: Auch in der FondInvestment-Klasse soll das Stock-Objekt mit dem Share Objekt ausgetauscht werden. Legen sie im FondInvestment zusätzlich einen neuen Konstruktor an, der eine Sammlung von Shares übergeben bekommt und den Fond-Preis aus der Summe der übergebenen Shares berechnet.
Nach dem Abschluss dieser Änderung soll die FondInvestment-Klasse folgende Methoden haben:
public FondInvestment(Share ... shares)
public FondInvestment(double price, Share ... shares)
public double netAssetValue() public double absolutePriceDelta()
public String toString()
public double projectedEarningsPerYear()
Was ich nicht verstanden habe ist diese Aussage " Legen sie im FondInvestment zusätzlich einen neuen Konstruktor an, der eine Sammlung von Shares übergeben bekommt und den Fond-Preis aus der Summe der übergebenen Shares berechnet. "
Ich habe 2 Konstruktoren mit gleichem Namen in einer Klasse. Also habe ich so geschrieben :
Code:
package de.tuberlin.ise.prog1.investments;
/**
* This calls stores a set of bought shares
*/
public class FondInvestment extends Investment{
//all stocks that are managed in this fond
private final Share[] shares;
//the original price of this fond
private final double price;
/**
* Creates a FondInvestment using a stocks-Array and price
* @param price
* @param stocks
*/
public FondInvestment(Share ... shares){
}
public FondInvestment(double price, Share ... shares) {
super();
this.price = price;
this.shares = shares;
}
/**
* Calculates the value of this investment by
* multiplying the amount by the current value of the brought stock
* @return value of this investment
*/
public double netAssetValue(){
double value = 0;
for(Share s:shares){
value+=s.currentValue();
}
return value;
}
/**
* Calculates the differences between
* the current value of this investment and the initial value of this investment
* @return
*/
public double absolutPriceDelta(){
return netAssetValue() - price;
}
@Override
public String toString() {
return "FondInvestment [id=" + getId() + ", currentValue()=" + netAssetValue()
+ ", absolutPriceDelta()=" + absolutPriceDelta() + "]";
}
@Override
public double projectedEarningsPerYear() {
// TODO Auto-generated method stub
return 0;
}
}