-
Notifications
You must be signed in to change notification settings - Fork 0
Lesson 4, my homework #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
Binary file modified
BIN
-24 Bytes
(99%)
out/production/ProjectJava/Lesson3/Lesson3HomeworkMultiDimensionalArray.class
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
out/production/ProjectJava/Lesson3/Lesson3HomeworkOneDimensionalArray.class
Binary file not shown.
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
| 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;} | ||
| 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("Ресурс выработан, компьютер сгорел"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
| 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(); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3
Компьютер сгорел
Компьютер не надо выключать, так как он сгорел
Это топчик))