forked from denyskon/info-java
38 lines
1.1 KiB
Java
Executable File
38 lines
1.1 KiB
Java
Executable File
import java.util.ArrayList;
|
|
|
|
public class Trader extends Person {
|
|
protected ArrayList<Aktie> aktien;
|
|
public Trader(String name, int age, double money) {
|
|
super(name, age, money);
|
|
this.aktien = new ArrayList<Aktie>();
|
|
}
|
|
public void aktieKaufen(String name, double price, int amt) {
|
|
Aktie aktie = new Aktie(name, amt, price);
|
|
this.aktien.add(aktie);
|
|
this.geldAuszahlen(aktie.getAktienWert());
|
|
}
|
|
public void aktieVerkaufen(String name, double price, int amt) {
|
|
for (Aktie aktie : this.aktien) {
|
|
if (aktie.getName() == name) {
|
|
this.geldEinzahlen(price * amt);
|
|
aktie.anzahlVerringern(amt);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
public double getPortfolioWert() {
|
|
double out = 0;
|
|
for (Aktie aktie : this.aktien) {
|
|
out += aktie.getAktienWert();
|
|
}
|
|
return out;
|
|
}
|
|
public void anzeigen() {
|
|
String out = "";
|
|
for (Aktie aktie : aktien) {
|
|
out += "\nAktie: " + aktie.getName() + ", Count: " + aktie.getCount() + ", Value: " + aktie.getValue();
|
|
}
|
|
System.out.println("Name: " + name + ", Age: " + age + ", Money: " + money + out + "\nGesamtwert: " + this.getPortfolioWert());
|
|
}
|
|
}
|