Beispiel #1
0
 public DVD(String tname, String tmodel, onetwo x)
     : base(tname, tmodel)
 {
     base.Speed = 21;
     storage    = 4700 * (int)x;
     GetInfo();
     base.Busy = 0;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            int need    = 565000;
            int onefile = 760;

            Console.WriteLine("how many storages you want? ");
            int amount;

            amount = Convert.ToInt32(Console.ReadLine());
            Storage[] stor = new Storage[amount];
            for (int i = 0; i < amount; i++)
            {
                Console.WriteLine("what is the name of the " + (i + 1) + " storage?\n");
                String tname = Console.ReadLine();
                Console.WriteLine("what is the model of the " + (i + 1) + " storage?\n");
                String tmodel = Console.ReadLine();
                switch (tmodel)
                {
                case "Flash":
                    Console.WriteLine("enter the storage of flash\n");
                    int     tstorage = Convert.ToInt32(Console.ReadLine());
                    Storage st       = new Flash(tname, tmodel, tstorage);
                    stor[i] = st;
                    break;

                case "DVD":
                    Console.WriteLine("enter the amount of size of DVD\n");
                    onetwo  ot  = (onetwo)int.Parse(Console.ReadLine());
                    Storage st1 = new DVD(tname, tmodel, ot);
                    stor[i] = st1;
                    break;

                case "HDD":
                    Console.WriteLine("enter the amount of sections of HDD\n");
                    int tsections = int.Parse(Console.ReadLine());
                    Console.WriteLine("enter the size of one section of HDD\n");
                    int     tstorage1 = int.Parse(Console.ReadLine());
                    Storage st2       = new HDD(tname, tmodel, tsections, tstorage1);
                    stor[i] = st2;
                    break;

                default:
                    Console.WriteLine("incorrect input, create FLASH\n");
                    Console.WriteLine("enter the storage of flash\n");
                    int     tstorage2 = Convert.ToInt32(Console.ReadLine());
                    Storage st4       = new Flash(tname, tmodel, tstorage2);
                    stor[i] = st4;
                    break;
                }
            }
            double time       = 0;
            int    needtocopy = need;

            Console.WriteLine("you need to copy {0} mb", need);
            while (need > 0)
            {
                time++;
                for (int i = 0; i < amount; i++)
                {
                    if (needtocopy == 0)
                    {
                        for (int j = 0; j < amount; j++)
                        {
                            stor[j].Flag = false;
                        }
                        break;
                    }
                    if (stor[i].Flag == true)
                    {
                        int free = stor[i].GetFreeSpace();
                        if (free < onefile)
                        {
                            stor[i].ChangeFlag();
                            continue;
                        }
                        if (needtocopy >= stor[i].Speed)
                        {
                            if (stor[i].GetFreeSpace() >= stor[i].Speed)
                            {
                                int willcopy = stor[i].Speed;
                                stor[i].Copy(willcopy);
                                needtocopy -= willcopy;
                            }
                            else
                            {
                                int willcopy = stor[i].GetFreeSpace();
                                stor[i].Copy(willcopy);
                                needtocopy -= willcopy;
                                stor[i].ChangeFlag();
                            }
                        }
                        else
                        {
                            if (needtocopy >= stor[i].GetFreeSpace())
                            {
                                int willcopy = stor[i].GetFreeSpace();
                                stor[i].Copy(willcopy);
                                needtocopy -= willcopy;
                                stor[i].ChangeFlag();
                            }
                            else
                            {
                                int willcopy = needtocopy;
                                needtocopy = 0;
                                stor[i].Copy(willcopy);
                            }
                        }
                    }
                }

                for (int i = 0; i < amount; i++)
                {
                    if (stor[i].Flag == false)
                    {
                        if (stor[i].Busy > stor[i].Speed)
                        {
                            int willwrite = stor[i].Speed;
                            stor[i].Write(willwrite);
                            need -= willwrite;
                        }
                        else
                        {
                            int willwrite = stor[i].Busy;
                            stor[i].Write(willwrite);
                            need -= willwrite;
                            stor[i].ChangeFlag();
                        }
                    }
                }
            }

            Console.WriteLine("with your storages it will take {0} sec", time);
        }