Created
September 30, 2016 23:46
-
-
Save tipochka/d38e5db58b7097547e100cb003599dea to your computer and use it in GitHub Desktop.
Блинов. Глава 4. Вариант А. 7 (*). Создать объект класса Компьютер, используя классы Винчестер, Дисковод, Оперативная память, Процессор. Методы: включить, выключить, проверить на вирусы, вывести на консоль размер винчестера.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Computer { | |
private Processor processor; | |
private List<Ram> ramList = new ArrayList<>(); | |
private List<HardDisc> hardDiscsList = new ArrayList<>(); | |
private boolean power = false; | |
public Computer(Processor processor, List<Ram> ramList, List<HardDisc> hardDiscsList) { | |
this.processor = processor; | |
this.ramList = ramList; | |
this.hardDiscsList = hardDiscsList; | |
} | |
public void switchOn() { | |
power = true; | |
} | |
public void switchOff() { | |
power = false; | |
} | |
public String checkVirus() { | |
//process check for virus | |
return "Checked"; | |
} | |
public void getSizeHardDisc() { | |
int size = 0; | |
for (HardDisc hardDisc : hardDiscsList) { | |
size += hardDisc.getSize(); | |
} | |
System.out.println(size); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ComputerRunner { | |
public static void main(String[] args) { | |
List<Ram> ramList = new ArrayList<>(); | |
ramList.add(new Ram(2)); | |
ramList.add(new Ram(2)); | |
List<HardDisc> hardDiscList = new ArrayList<>(); | |
hardDiscList.add(new HardDisc(500)); | |
hardDiscList.add(new HardDisc(1000)); | |
Computer computer = new Computer(new Processor(), ramList, hardDiscList); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HardDisc { | |
private final int size; | |
public HardDisc(int size) { | |
this.size = size; | |
} | |
public int getSize() { | |
return size; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Processor { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Ram { | |
private final int size; | |
public Ram(int size) { | |
this.size = size; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment