Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- namespace Reszveny
- {
- public enum Reszvenytipusok
- {
- IBM, TSLA, NFLX, GOOGL, FB, NVDA, MSFT, AAPL, AMZN
- }
- public class Tulajdonos
- {
- public int db;
- public decimal arfolyam; List<Reszvenytipusok> reszvenylista;
- bool isAdossag;
- private decimal adossag;
- public decimal Adossag
- {
- get
- {
- return adossag;
- }
- set
- {
- adossag = value;
- }
- }
- public List<Reszveny> reszvenyek;
- public Tulajdonos(string nev, decimal penz)
- {
- reszvenylista = new List<Reszvenytipusok>();
- reszvenyek = new List<Reszveny>();
- this.nev = nev;
- this.penz = penz;
- }
- private string nev;
- public string Nev
- {
- get
- {
- return nev;
- }
- set
- {
- nev = value;
- }
- }
- private decimal penz;
- public decimal Penz
- {
- get
- {
- return penz;
- }
- set
- {
- penz = value;
- }
- }
- public string PrintTulajdon()
- {
- string adat = "";
- adat += "Reszveny Tulajdonosa: " + this.Nev + Environment.NewLine;
- adat += "Keszpenz: $" + this.Penz + Environment.NewLine;
- adat += Environment.NewLine;
- if (isAdossag)
- {
- this.Adossag = -(this.Penz);
- adat += "Adossag: $" + this.Adossag + Environment.NewLine;
- }
- adat += Environment.NewLine;
- int count = 0;
- foreach (var item in reszvenyek)
- {
- adat += count + ".";
- adat += "Nev: " + item.Nev + Environment.NewLine;
- adat += "Arfolyam: $" + item.Arfolyam + Environment.NewLine;
- adat += "Darab: " + item.Db + Environment.NewLine;
- adat += Environment.NewLine;
- count++;
- }
- if (reszvenyek.Capacity == 0)
- {
- adat = this.Nev + "tulajdonaban nincs reszveny!";
- }
- return adat;
- }
- public List<string> GetTulajdon()
- {
- List<string> tulajdon = new List<string>();
- tulajdon.Add(this.Nev);
- tulajdon.Add(Environment.NewLine);
- tulajdon.Add(this.Penz.ToString());
- tulajdon.Add(Environment.NewLine);
- if (isAdossag)
- {
- this.Adossag = -(this.Penz);
- tulajdon.Add(this.Adossag.ToString());
- }
- else
- {
- tulajdon.Add("0");
- }
- tulajdon.Add(Environment.NewLine);
- foreach (var item in reszvenyek)
- {
- tulajdon.Add(item.Nev);
- tulajdon.Add(Environment.NewLine);
- tulajdon.Add(item.Arfolyam.ToString());
- tulajdon.Add(Environment.NewLine);
- tulajdon.Add(item.Db.ToString());
- tulajdon.Add(Environment.NewLine);
- }
- if (reszvenyek.Capacity == 0)
- {
- tulajdon.Add(this.Nev + "tulajdonaban nincs reszveny!");
- }
- return tulajdon;
- }
- public bool isTulajdon()
- {
- bool tulajdon = true;
- if (reszvenyek.Capacity == 0)
- {
- tulajdon = false;
- }
- return tulajdon;
- }
- public List<Reszvenytipusok> Vetel(Reszveny reszveny)
- {
- reszvenyek.Add(reszveny);
- penz -= reszveny.Arfolyam * reszveny.Db;
- if (penz < 0)
- {
- isAdossag = true;
- adossag = penz;
- }
- return reszvenylista;
- }
- public List<Reszvenytipusok> Eladas(int valasz)
- {
- penz += reszvenyek.ElementAt(valasz).Arfolyam * reszvenyek.ElementAt(valasz).Db;
- reszvenyek.RemoveAt(valasz);
- return reszvenylista;
- }
- public void SaveGame(List<string> adat)
- {
- string text = "";
- foreach (var item in adat)
- {
- text += item;
- }
- File.WriteAllText(@"D:\teszt.txt", text);
- }
- public void LoadGame(List<string> adat)
- {
- string[] lines = new string[] { };
- if (File.Exists(@"D:\teszt.txt"))
- {
- lines = File.ReadAllLines(@"D:\teszt.txt");
- Console.WriteLine("elmentett fajl tartalma: ");
- if (!lines.Any())
- {
- Console.WriteLine("Ures");
- }
- else
- {
- foreach (string line in lines)
- {
- Console.WriteLine("\t" + line);
- }
- }
- int count = 0;
- foreach (var item in adat)
- {
- switch (count)
- {
- case 0:
- Nev = item;
- break;
- case 1:
- Penz = Decimal.Parse(item);
- break;
- case 2:
- Adossag = Decimal.Parse(item);
- break;
- case 3:
- Nev = item;
- break;
- case 4:
- arfolyam = Decimal.Parse(item);
- break;
- case 5:
- db = Int32.Parse(item);
- break;
- default:
- break;
- }
- count++;
- }
- }
- else
- {
- this.SaveGame(this.GetTulajdon());
- }
- }
- public List<string> LoadData()
- {
- List<string> data = new List<string>();
- if (File.Exists(@"D:\teszt.txt"))
- {
- using (StreamReader reader = new StreamReader(@"D:\teszt.txt"))
- {
- string s = reader.ReadLine();
- while (s != null)
- {
- data.Add(s);
- s = reader.ReadLine();
- }
- }
- }
- else
- {
- data = null;
- }
- return data;
- }
- public class Reszveny
- {
- public List<string> ReszvenyNevek;
- private string nev;
- private decimal arfolyam;
- private decimal vetelArfolyam;
- public int db;
- public Reszvenytipusok tipus;
- public Reszveny(Reszvenytipusok tipus, int db)
- {
- this.tipus = tipus;
- this.db = db;
- }
- public Reszveny()
- {
- ReszvenyNevek = new List<string>();
- }
- public Reszveny(string nev, decimal arfolyam, int db)
- {
- this.nev = nev;
- this.arfolyam = arfolyam;
- this.db = db;
- ReszvenyNevek = new List<string>();
- }
- public string Nev
- {
- get
- {
- return nev;
- }
- set
- {
- nev = value;
- }
- }
- public int Db
- {
- get
- {
- return db;
- }
- set
- {
- db = value;
- }
- }
- public decimal Arfolyam
- {
- get
- {
- return arfolyam;
- }
- set
- {
- arfolyam = value;
- }
- }
- public decimal VetelArfolyam
- {
- get
- {
- return vetelArfolyam;
- }
- set
- {
- vetelArfolyam = value;
- }
- }
- public decimal ArfolyamValtozas(double szazalek)
- {
- szazalek /= 100;
- this.Arfolyam = this.Arfolyam + this.Arfolyam * (decimal)szazalek;
- return this.Arfolyam;
- }
- public void VisszaAllitas()
- {
- this.nev = "";
- this.arfolyam = 0;
- this.db = 0;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- if (!File.Exists(@"D:\teszt.txt"))
- {
- File.Create(@"D:\teszt.txt");
- }
- List<string> ReszvenyNevek = Enum.GetNames(typeof(Reszvenytipusok)).ToList();
- List<Tulajdonos.Reszveny> reszvenyek = new List<Tulajdonos.Reszveny>();
- Tulajdonos John = new Tulajdonos("John", 1000);
- string tovabb = "";
- string eladvesz = "";
- List<string> lista = new List<string>();
- lista = John.LoadData();
- while (tovabb != "n")
- {
- John.LoadGame(lista);
- try
- {
- John.PrintTulajdon();
- Console.WriteLine();
- Console.WriteLine("Reszvenyt (V)enni vagy (E)ladni szeretne?");
- eladvesz = Console.ReadLine();
- if (eladvesz == "e" || eladvesz == "E")
- {
- try
- {
- Console.Clear();
- Console.WriteLine("Valassza ki milyen reszvenyt szeretne eladni a tulajdonabol: ");
- if (John.isTulajdon())
- {
- Console.WriteLine(John.PrintTulajdon());
- Console.WriteLine();
- int valasz = Convert.ToInt32(Console.ReadLine());
- John.Eladas(valasz);
- Console.Clear();
- }
- else
- {
- Console.Clear();
- Console.WriteLine("Nincs tulajdonaban reszveny!");
- Console.WriteLine();
- }
- }
- catch (Exception)
- {
- Console.Clear();
- Console.WriteLine("Ervenytelen Utasitas!");
- Console.WriteLine();
- }
- }
- else
- {
- try
- {
- Console.Clear();
- Console.WriteLine("Valassza ki milyen reszvenyt szeretne venni: ");
- int count = 0;
- foreach (var item in ReszvenyNevek)
- {
- Console.WriteLine(count + ": " + item);
- count++;
- }
- int valasz = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Hany darab reszvenyt szeretne vasarolni");
- int darab = Convert.ToInt32(Console.ReadLine());
- Tulajdonos.Reszveny reszveny = new Tulajdonos.Reszveny() { Db = darab, Nev = ((Reszvenytipusok)valasz).ToString(), Arfolyam = 25 };
- John.Vetel(reszveny);
- foreach (var item in John.reszvenyek)
- {
- Random random = new Random();
- double arfolyamvaltozas = random.Next(-15, 15);
- reszveny.ArfolyamValtozas(arfolyamvaltozas);
- }
- Console.Clear();
- }
- catch (Exception)
- {
- Console.WriteLine("Ervenytelen Utasitas!");
- }
- }
- Console.WriteLine(John.PrintTulajdon());
- Console.WriteLine();
- John.SaveGame(John.GetTulajdon());
- lista.Add(John.GetTulajdon().ToString());
- Console.Clear();
- Console.WriteLine("Szeretnel tovabb kereskedni reszvenyel? (I/N)");
- Console.WriteLine("Jo hirunk van szamara. Valtoztak a Reszveny arak.");
- tovabb = Console.ReadLine();
- Console.Clear();
- Console.WriteLine(John.PrintTulajdon());
- Console.WriteLine();
- }
- catch (Exception e)
- {
- Console.Clear();
- Console.WriteLine("Ervenytelen Utasitas!");
- Console.WriteLine(e);
- Console.WriteLine(John.PrintTulajdon());
- }
- }
- Console.Clear();
- Console.WriteLine(John.PrintTulajdon());
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement