public void OverChargeBatteryTest()
        {
            RAM laptopRAM = new RAM(4);
            var laptopVideoCard = new VideoCard(false);
            var laptopHardDrives = new[] { new HardDrive(500, false, 0) };
            var laptopBattery = new LaptopBattery();
            var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

            Computer laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            laptop.ChargeBattery(300);
        }
        public static void Main()
        {
            var manufacturer = Console.ReadLine();
            if (manufacturer == "HP")
            {
                var personalComputerRAM = new RAM(2);
                var personalComputerVideoCard = new VideoCard(false);
                var personalComputerHardDrives = new[] { new HardDrive(500, false, 0) };
                var personalComputerCPU = new CPU(2, CPUTypes._32bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(32);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(1000, false, 0), new HardDrive(1000, false, 0) }) };
                var serverCPU = new CPU(4, CPUTypes._32bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(4);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(500, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else if (manufacturer == "Dell")
            {
                var personalComputerRAM = new RAM(8);
                var personalComputerVideoCard = new VideoCard(false);
                var personalComputerHardDrives = new[] { new HardDrive(1000, false, 0) };
                var personalComputerCPU = new CPU(4, CPUTypes._64bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(64);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(2000, false, 0), new HardDrive(2000, false, 0) }) };
                var serverCPU = new CPU(8, CPUTypes._64bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(8);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(1000, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(4, CPUTypes._32bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else if (manufacturer == "Lenovo")
            {
                var personalComputerRAM = new RAM(4);
                var personalComputerVideoCard = new VideoCard(true);
                var personalComputerHardDrives = new[] { new HardDrive(2000, false, 0) };
                var personalComputerCPU = new CPU(2, CPUTypes._64bit, personalComputerRAM, personalComputerVideoCard);

                personalComputer = new Computer(ComputerType.PC, personalComputerCPU, personalComputerRAM, personalComputerHardDrives, personalComputerVideoCard, null);

                var serverRAM = new RAM(8);
                var serverVideoCard = new VideoCard();
                var serverHardDrives = new List<HardDrive> { new HardDrive(0, true, 2, new List<HardDrive> { new HardDrive(500, false, 0), new HardDrive(500, false, 0) }) };
                var serverCPU = new CPU(2, CPUTypes._128bit, serverRAM, serverVideoCard);

                server = new Computer(ComputerType.SERVER, serverCPU, serverRAM, serverHardDrives, serverVideoCard, null);

                var laptopRAM = new RAM(16);
                var laptopVideoCard = new VideoCard(false);
                var laptopHardDrives = new[] { new HardDrive(1000, false, 0) };
                var laptopBattery = new LaptopBattery();
                var laptopCPU = new CPU(2, CPUTypes._64bit, laptopRAM, laptopVideoCard);

                laptop = new Computer(ComputerType.LAPTOP, laptopCPU, laptopRAM, laptopHardDrives, laptopVideoCard, laptopBattery);
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            var command = Console.ReadLine();

            while (command != null && command != "Exit")
            {
                var commandArguments = command.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandArguments.Length != 2)
                {
                    throw new ArgumentException("Invalid command!");
                }

                var commandName = commandArguments[0];
                var commandParameter = int.Parse(commandArguments[1]);
                if (commandName == "Charge")
                {
                    laptop.ChargeBattery(commandParameter);
                }
                else if (commandName == "Process")
                {
                    server.Process(commandParameter);
                }
                else if (commandName == "Play")
                {
                    personalComputer.Play(commandParameter);
                }

                command = Console.ReadLine();
            }
        }
        public static void Main()
        {
            var manufacturer = Console.ReadLine();
            if (manufacturer == "HP")
            {
                var hp = new HpFactory();
                var factoryBuilder = new FactoryBuilder(hp);
                pc = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else if (manufacturer == "Dell")
            {
                var dell = new DellFactory();
                var factoryBuilder = new FactoryBuilder(dell);
                pc = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else if (manufacturer == "Lenovo")
            {
                var lenovo = new LenovoFactory();
                var factoryBuilder = new FactoryBuilder(lenovo);
                pc = factoryBuilder.MakePersonalComputer();
                laptop = factoryBuilder.MakeLaptop();
                server = factoryBuilder.MakeServer();
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            while (true)
            {
                var inputLine = Console.ReadLine();
                if (inputLine == null || inputLine.StartsWith("Exit"))
                {
                    break;
                }

                var commandParameters = inputLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandParameters.Length != 2)
                {
                    throw new ArgumentException("Invalid command, command should consist of two parameters");
                }

                var command = commandParameters[0];
                var parameter = int.Parse(commandParameters[1]);

                if (command == "Charge")
                {
                    laptop.Execute(parameter);
                }
                else if (command == "Process")
                {
                    server.Execute(parameter);
                }
                else if (command == "Play")
                {
                    pc.Execute(parameter);
                }
                else
                {
                    Console.WriteLine("Invalid command, there are three types of commands - Play, Charge, Process");
                }
            }
        }
Exemple #4
0
        public static void Main()
        {
            var manufacturer = Console.ReadLine();
            if (manufacturer == "HP")
            {
                var ram = new Rammstein(2);
                var videoCard = new HardDriver() { IsMonochrome = false };

                pc = new Computer(ComputerType.PC,
                    new Cpu(2, 32, ram, videoCard),
                    ram,
                    new[] { new HardDriver(500, false, 0) },
                    videoCard, null);

                var serverRam = new Rammstein(32);
                var serverVideo = new HardDriver();

                server = new Computer(
                    ComputerType.SERVER,
                    new Cpu(4,
                        32, serverRam, serverVideo),
                    serverRam,
                    new List<HardDriver>{
                            new HardDriver(0, true, 2,
                                new List<HardDriver> { new HardDriver(1000, false, 0),
                                    new HardDriver(1000, false, 0) })
                        },
                        serverVideo, null);
                {
                    var card = new HardDriver()
                    {
                        IsMonochrome
                            = false
                    };

                    var ram1 = new Rammstein(4);
                    laptop = new Computer(
                        ComputerType.LAPTOP,
                        new Cpu(4, 64, ram1, card),
                        ram1,
                        new[]
                            {
                                new HardDriver(500,
                                    false, 0)
                            },
                        card, new LaptopBattery());
                }
            }
            else if (manufacturer == "Dell")
            {
                var ram = new Rammstein(8);
                var videoCard = new HardDriver() { IsMonochrome = false };

                pc = new Computer(ComputerType.PC,
                    new Cpu(4, 64, ram, videoCard), ram,
                    new[] { new HardDriver(1000, false, 0) },
                    videoCard, null);
                var ram1 = new Rammstein(64);
                var card = new HardDriver();

                server = new Computer(ComputerType.SERVER,
                     new Cpu(8, 64, ram1, card),
                     ram1,
                     new List<HardDriver>{
                            new HardDriver(0, true, 2,
                                new List<HardDriver> { new HardDriver(2000, false, 0),
                                    new HardDriver(2000, false, 0) })
                        }, card, null);

                var ram2 = new Rammstein(8);
                var videoCard1 = new HardDriver() { IsMonochrome = false };
                laptop = new Computer(ComputerType.LAPTOP,
                    new Cpu(4, ((32)), ram2, videoCard1),
                    ram2,
                    new[] { new HardDriver(1000, false, 0) },
                    videoCard1,
                    new LaptopBattery());
            }
            else
            {
                throw new InvalidArgumentException("Invalid manufacturer!");
            }

            while (true)
            {
                var c = Console.ReadLine();
                if (c == null)
                {
                    break;
                }
                if (c.StartsWith("Exit"))
                {
                    break;
                }

                var cp = c.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (cp.Length != 2)
                {
                    {
                        throw new ArgumentException("Invalid command!");
                    }
                }

                var cn = cp[0];
                var ca = int.Parse(cp[1]);

                if (cn == "Charge")
                {
                    laptop.ChargeBattery(ca);
                }
                else if (cn == "Process")
                {
                    server.Process(ca);
                }
                else if (cn == "Play")
                {
                    pc.Play(ca);
                }

                Console.WriteLine("Invalid command!");
            }
        }