Advertisement
csaki

II_2 4. gyak tablet storage stb

Feb 26th, 2013
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace II_2_4.gyak_1
  7. {
  8.     class tablet
  9.     {
  10.         protected int _res_x;
  11.         protected int _res_y;
  12.         protected double _android_ver;
  13.         public bool camera;
  14.         public bool gps;
  15.         protected int _cost;
  16.  
  17.         private static double[] verziok = new double[] { 4.0, 4.1, 4.2 };
  18.         private static int[] tomb_resx = new int[] { 640, 800, 1024 };
  19.         private static int[] tomb_resy = new int[] { 480, 600, 768 };
  20.  
  21.         // x,y helyes beállítása
  22.         public void set_xy(int x, int y)
  23.         {
  24.             int i = Array.IndexOf(tomb_resx, x);
  25.             int j = Array.IndexOf(tomb_resy, y);
  26.             if (i == -1 || j == -1) throw new Exception("Nincs ilyen felbontás");
  27.             if (i != j) throw new Exception("Nem stimmelnek a felbontások!");
  28.             _res_x = x;
  29.             _res_y = y;
  30.         }
  31.  
  32.         // constructor
  33.         public tablet(int x, int y, double ver, bool iscam, bool isgps, int pcost)
  34.         {
  35.             set_xy(x, y);
  36.             android_ver = ver;
  37.             camera = iscam;
  38.             gps = isgps;
  39.             cost = pcost;
  40.         }
  41.  
  42.         public tablet(int x, int y, double ver, int pcost)
  43.             : this(x, y, ver, false, false, pcost) { }
  44.  
  45.         public tablet(int pcost)
  46.             : this(tomb_resx[0], tomb_resy[1], verziok[0], false, false, pcost) { }
  47.  
  48.         // property
  49.         public int res_x // 640, 800, 1024
  50.         {
  51.             get
  52.             {
  53.                 return _res_x;
  54.             }
  55.         }
  56.         public int res_y // 480, 600, 768
  57.         {
  58.             get
  59.             {
  60.                 return _res_y;
  61.             }
  62.         }
  63.         public double android_ver // 4.0, 4.1, 4.2
  64.         {
  65.             set
  66.             {
  67.                 if (Array.IndexOf(verziok, value) == -1) throw new Exception("Nincs ilyen verzió!");
  68.                 _android_ver = value;
  69.             }
  70.             get
  71.             {
  72.                 return _android_ver;
  73.             }
  74.         }
  75.  
  76.         public int cost // 10 000 - 800 000
  77.         {
  78.             set
  79.             {
  80.                 if (10000 < value && value < 800000)
  81.                 {
  82.                     _cost = value;
  83.                 }
  84.                 else throw new Exception("Nem megfelelő ár!");
  85.             }
  86.             get
  87.             {
  88.                 return _cost;
  89.             }
  90.         }
  91.     }
  92.  
  93.     class storage
  94.     {
  95.         List<tablet> tlista = new List<tablet>();
  96.  
  97.         // hozzáadás
  98.         public void hozzaad(tablet t)
  99.         {
  100.             if (t != null)
  101.             {
  102.                 tlista.Add(t);
  103.             }
  104.             else throw new Exception("Nem lehet null érték!");
  105.         }
  106.  
  107.         // törlés (random törlés)
  108.         public void random_torles()
  109.         {
  110.             Random rand = new Random();
  111.             tlista.RemoveAt(rand.Next(tlista.Count));
  112.         }
  113.  
  114.         // darabszám kiolvasás
  115.         public int darabszam
  116.         {
  117.             get
  118.             {
  119.                 return tlista.Count;
  120.             }
  121.         }
  122.  
  123.         // összérték
  124.         public int ossz
  125.         {
  126.             get
  127.             {
  128.                 int sum = 0;
  129.                 foreach (var x in tlista)
  130.                 {
  131.                     sum += x.cost;
  132.                 }
  133.                 return ossz;
  134.             }
  135.         }
  136.     }
  137.  
  138.     class Program
  139.     {
  140.         static void Main(string[] args)
  141.         {
  142.             // tesztprogram
  143.             while (true)
  144.             {
  145.                 Console.WriteLine("1. Random létrehozás és raktárfeltöltés");
  146.                 Console.WriteLine("2. Manuális hozzáadás");
  147.                 Console.WriteLine("3. Random törlés");
  148.                 Console.WriteLine("4. Konkrét törlés");
  149.                 Console.WriteLine("5. Darabszám kiolvasása");
  150.                 Console.WriteLine("6. Total cost");
  151.                 Console.WriteLine();
  152.  
  153.                 int menu = int.Parse(Console.ReadLine());
  154.                
  155.                 storage stor = new storage();
  156.                 Random rand = new Random();
  157.                 int[] xtomb = new int[] { 640, 800, 1024 };
  158.                 int[] ytomb = new int[] { 480, 600, 768 };
  159.                 double[] vertomb = new double[] { 4.0, 4.1, 4.2 };
  160.  
  161.                 switch (menu)
  162.                 {
  163.                     case 1:
  164.                         // TODO
  165.                         Console.WriteLine("Hány tabletet akarsz a raktárba rakni?");
  166.                         int szam = int.Parse(Console.ReadLine());
  167.  
  168.                         for (int i = 0; i < szam; i++)
  169.                         {
  170.                             int xy = rand.Next(xtomb.Length);
  171.                             int x = xtomb[rand.Next(xy)];
  172.                             int y = ytomb[rand.Next(xy)];
  173.                             xy = rand.Next(vertomb.Length);
  174.                             double ver = vertomb[rand.Next(xy)];
  175.                             bool cam = rand.Next(1) == 0 ? false : true;
  176.                             bool gps = rand.Next(1) == 0 ? false : true;
  177.                             int cost = rand.Next(10000, 800001);
  178.                             tablet tab = new tablet(x, y, ver, cam, gps, cost);
  179.                             stor.hozzaad(tab);
  180.                         }
  181.                         break;
  182.  
  183.                     case 2:
  184.                         // TODO
  185.  
  186.                         // stor.hozzaad(tab);
  187.                         break;
  188.  
  189.                     case 3:
  190.                         stor.random_torles();
  191.                         break;
  192.  
  193.                     case 4:
  194.                         // TODO - függvényt meg kell írni!
  195.                         break;
  196.  
  197.                     case 5:
  198.                         Console.WriteLine("Darabszám: {0}", stor.darabszam);
  199.                         break;
  200.  
  201.                     case 6:
  202.                         Console.WriteLine("Össz ár: {0}", stor.ossz);
  203.                         break;
  204.  
  205.                     default:
  206.                         Console.WriteLine("Hibás menüpont!");
  207.                         break;
  208.                 }
  209.             }
  210.         }
  211.     }
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement