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;
- namespace II_2_4.gyak_1
- {
- class tablet
- {
- protected int _res_x;
- protected int _res_y;
- protected double _android_ver;
- public bool camera;
- public bool gps;
- protected int _cost;
- private static double[] verziok = new double[] { 4.0, 4.1, 4.2 };
- private static int[] tomb_resx = new int[] { 640, 800, 1024 };
- private static int[] tomb_resy = new int[] { 480, 600, 768 };
- // x,y helyes beállítása
- public void set_xy(int x, int y)
- {
- int i = Array.IndexOf(tomb_resx, x);
- int j = Array.IndexOf(tomb_resy, y);
- if (i == -1 || j == -1) throw new Exception("Nincs ilyen felbontás");
- if (i != j) throw new Exception("Nem stimmelnek a felbontások!");
- _res_x = x;
- _res_y = y;
- }
- // constructor
- public tablet(int x, int y, double ver, bool iscam, bool isgps, int pcost)
- {
- set_xy(x, y);
- android_ver = ver;
- camera = iscam;
- gps = isgps;
- cost = pcost;
- }
- public tablet(int x, int y, double ver, int pcost)
- : this(x, y, ver, false, false, pcost) { }
- public tablet(int pcost)
- : this(tomb_resx[0], tomb_resy[1], verziok[0], false, false, pcost) { }
- // property
- public int res_x // 640, 800, 1024
- {
- get
- {
- return _res_x;
- }
- }
- public int res_y // 480, 600, 768
- {
- get
- {
- return _res_y;
- }
- }
- public double android_ver // 4.0, 4.1, 4.2
- {
- set
- {
- if (Array.IndexOf(verziok, value) == -1) throw new Exception("Nincs ilyen verzió!");
- _android_ver = value;
- }
- get
- {
- return _android_ver;
- }
- }
- public int cost // 10 000 - 800 000
- {
- set
- {
- if (10000 < value && value < 800000)
- {
- _cost = value;
- }
- else throw new Exception("Nem megfelelő ár!");
- }
- get
- {
- return _cost;
- }
- }
- }
- class storage
- {
- List<tablet> tlista = new List<tablet>();
- // hozzáadás
- public void hozzaad(tablet t)
- {
- if (t != null)
- {
- tlista.Add(t);
- }
- else throw new Exception("Nem lehet null érték!");
- }
- // törlés (random törlés)
- public void random_torles()
- {
- Random rand = new Random();
- tlista.RemoveAt(rand.Next(tlista.Count));
- }
- // darabszám kiolvasás
- public int darabszam
- {
- get
- {
- return tlista.Count;
- }
- }
- // összérték
- public int ossz
- {
- get
- {
- int sum = 0;
- foreach (var x in tlista)
- {
- sum += x.cost;
- }
- return ossz;
- }
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- // tesztprogram
- while (true)
- {
- Console.WriteLine("1. Random létrehozás és raktárfeltöltés");
- Console.WriteLine("2. Manuális hozzáadás");
- Console.WriteLine("3. Random törlés");
- Console.WriteLine("4. Konkrét törlés");
- Console.WriteLine("5. Darabszám kiolvasása");
- Console.WriteLine("6. Total cost");
- Console.WriteLine();
- int menu = int.Parse(Console.ReadLine());
- storage stor = new storage();
- Random rand = new Random();
- int[] xtomb = new int[] { 640, 800, 1024 };
- int[] ytomb = new int[] { 480, 600, 768 };
- double[] vertomb = new double[] { 4.0, 4.1, 4.2 };
- switch (menu)
- {
- case 1:
- // TODO
- Console.WriteLine("Hány tabletet akarsz a raktárba rakni?");
- int szam = int.Parse(Console.ReadLine());
- for (int i = 0; i < szam; i++)
- {
- int xy = rand.Next(xtomb.Length);
- int x = xtomb[rand.Next(xy)];
- int y = ytomb[rand.Next(xy)];
- xy = rand.Next(vertomb.Length);
- double ver = vertomb[rand.Next(xy)];
- bool cam = rand.Next(1) == 0 ? false : true;
- bool gps = rand.Next(1) == 0 ? false : true;
- int cost = rand.Next(10000, 800001);
- tablet tab = new tablet(x, y, ver, cam, gps, cost);
- stor.hozzaad(tab);
- }
- break;
- case 2:
- // TODO
- // stor.hozzaad(tab);
- break;
- case 3:
- stor.random_torles();
- break;
- case 4:
- // TODO - függvényt meg kell írni!
- break;
- case 5:
- Console.WriteLine("Darabszám: {0}", stor.darabszam);
- break;
- case 6:
- Console.WriteLine("Össz ár: {0}", stor.ossz);
- break;
- default:
- Console.WriteLine("Hibás menüpont!");
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement