Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Lesson4/Урок 4 ДЗ.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
93 changes: 93 additions & 0 deletions src/Lesson4/Computer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package Lesson4;

import java.util.Random;
import java.util.Scanner;

public class Computer {
private String cpu;
private String ram;
private String ssd;
private int resource;
boolean condition = false; //true - включен, false - выключен

public Computer(String cpu, String ram, String ssd, int resource) {
this.cpu = cpu;
this.ram = ram;
this.ssd = ssd;
this.resource = resource;
}

public String getCpu() {
return cpu;
}

public void setCpu(String cpu) {
this.cpu = cpu;
}

public String getRam() {
return ram;
}

public void setRam(String ram) {
this.ram = ram;
}

public String getSsd() {
return ssd;
}

public void setSsd(String ssd) {
this.ssd = ssd;
}

public int getResource() {
return resource;
}

public void setResource(int resource) {
this.resource = resource;
}
public void description(){
System.out.println("Процессор на этом компьютере "+getCpu());
System.out.println("Оперативная память на этом компьютере "+getRam());
System.out.println("Жесткий диск на этом компьютере "+getSsd());
System.out.println("Ресурс полных циклов работы равен "+getResource());
}
public void turnOn(){
if (resource==0) {System.out.println("Компьютер не включится, так как он сгорел"); return;}
if (condition) System.out.println("Компьютер уже итак включен");
else{
Random random = new Random();
int numberRandom=random.nextInt(2);
Scanner scanner=new Scanner(System.in);
int numberMine=scanner.nextInt();
if (numberRandom!=numberMine) {
System.out.println("Компьютер сгорел");
resource=0;}
else {
System.out.println("Компьютер включен");
condition=true;
}
}
}
public void turnOff(){
if (resource==0) {System.out.println("Компьютер не надо выключать, так как он сгорел"); return;}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3
Компьютер сгорел

Компьютер не надо выключать, так как он сгорел
Это топчик))

if (!condition) System.out.println("Компьютер уже итак выключен");
else {
Random random = new Random();
int numberRandom=random.nextInt(2);
Scanner scanner=new Scanner(System.in);
int numberMine=scanner.nextInt();
if (numberRandom!=numberMine) {
System.out.println("Компьютер сгорел");
resource=0;}
else {
System.out.println("Компьютер выключен");
condition=false;
resource-=1;
if (resource==0) System.out.println("Ресурс выработан, компьютер сгорел");
}
}
}
}
19 changes: 19 additions & 0 deletions src/Lesson4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package Lesson4;

public class Main {
public static void main(String[] args) {
Computer myComputer = new Computer("Apple M1", "8 Gb", "512 Gb", 2);
String macCpu = myComputer.getCpu();
String macRam = myComputer.getRam();
String macSsd = myComputer.getSsd();
int macResource = myComputer.getResource();

myComputer.description();
while (myComputer.getResource() > 0) {
System.out.println();
myComputer.turnOn();
System.out.println();
myComputer.turnOff();
}
}
}