public void RemoveStock(ConcreteStocks stock) { stock.detach(this); stockList.Remove(stock); TotalValue = stock.ValueOfSubject * 0; Console.WriteLine("\nRemoving " + stock + " from Portfolio: " + this.Name); }
public void Update(ConcreteStocks name) { TotalValue = 0; foreach (var VARIABLE in stockList) { TotalValue += VARIABLE.ValueOfSubject * VARIABLE.AmountOfSubject; } foreach (var VARIABLE in stockList) { if (VARIABLE.NameOfSubject == name.NameOfSubject) { Display.PrintPF(this); } } foreach (var VARIABLE in stockList) { if (VARIABLE.NameOfSubject == name.NameOfSubject) //Find navnet på stocken/subject { VARIABLE.ValueOfSubject = VARIABLE.ValueOfSubject * VARIABLE.AmountOfSubject; //Override med den nye valuta ganget ind med antallet af aktier man har } } }
public void AddStock(ConcreteStocks stock) { stock.attach(this); //Attacher whatever man vil attach, men den skal helst have portfolio ind Ellers dør baby! stockList.Add(stock); //Adder stock til listen hvor stock er navn, valuta, og antal TotalValue = stock.ValueOfSubject + TotalValue; Console.WriteLine("\nAdding " + stock + " to Portfolio: " + this.Name); }
//Når vi notificere observeren, så opdateres der /*public void notify() * { * foreach (var observers in ObserversList) * { * observers.Update(_ticker, _value); * } * }*/ public void notify(ConcreteStocks stock) { foreach (var observers in ObserversList) { observers.Update(stock); } }
static void Main(string[] args) { //Tror stock skal bruges til notifikationsdelen var stock = new Stock(); //Viser display var etDisplay = new PortfolioDisplay(); //Laver et nyt portfolio i listen med navnet Hans, med display var enPortfolio = new Portfolio("Hans", etDisplay); var toPortfolio = new Portfolio("Eckhart", etDisplay); //Laver stocks var enStock = new ConcreteStocks("VESTAS", 570.50, 1); var toStock = new ConcreteStocks("GOOGLE", 943.29, 1); //Console.WriteLine(stock); //etDisplay.PrintPF(enPortfolio); //Tilføjer //Console.WriteLine("\nAdding VESTAS"); enPortfolio.AddStock(enStock); //etDisplay.PrintPF(enPortfolio); //Console.WriteLine("\nAdding GOOGLE"); enPortfolio.AddStock(toStock); //etDisplay.PrintPF(enPortfolio); toPortfolio.AddStock(enStock); //Updatere Random number = new Random(); int counter = 0; while (counter < 5) { Thread.Sleep(1000); double number1 = number.NextDouble() * (enStock.ValueOfSubject * 1.05 - enStock.ValueOfSubject * 0.95) + enStock.ValueOfSubject * 0.95; //Det her giver mig mellem 95 og 105 procent enStock.setValue(number1); counter++; } //Console.WriteLine("\nUpdating VESTAS"); //etDisplay.PrintPF(enPortfolio); //etDisplay.PrintPF(toPortfolio); //Notifikation //Console.WriteLine("\nNotifikation: Ændring af VESTAS til DINMOR"); enStock.setName("DINMOR"); //etDisplay.PrintPF(enPortfolio); //etDisplay.PrintPF(toPortfolio); ; //Fjerner //Console.WriteLine("\nRemoving VESTAS"); enPortfolio.RemoveStock(enStock); //etDisplay.PrintPF(enPortfolio); while (counter < 10) { Thread.Sleep(1000); double number1 = number.NextDouble() * (toStock.ValueOfSubject * 1.05 - toStock.ValueOfSubject * 0.95) + toStock.ValueOfSubject * 0.95; //Det her giver mig mellem 95 og 105 procent toStock.setValue(number1); counter++; } }