Created
February 12, 2014 15:34
-
-
Save Vox1oot/8957729 to your computer and use it in GitHub Desktop.
package com.javarush.test.level16.lesson05.task03
This file contains 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
package com.javarush.test.level16.lesson05.task03; | |
/* Продвижение на политических дебатах | |
1. Разберитесь, что делает программа. | |
2. Нужно сделать так, чтобы Иванов сказал больше всего речей на политических дебатах. | |
3. Подумай, какой метод можно вызвать у объекта ivanov, чтобы Иванов разговаривал, пока не завершится всё свободное время. | |
*/ | |
public class Solution { | |
public static int totalCountSpeeches = 200; | |
public static int soundsInOneSpeech = 1000000; | |
public static void main(String[] args) throws InterruptedException { | |
Politic ivanov = new Politic("Иванов"); | |
ivanov.join(); | |
Politic petrov = new Politic("Петров"); | |
Politic sidorov = new Politic("Сидоров"); | |
while (ivanov.getCountSpeaches() + petrov.getCountSpeaches() + sidorov.getCountSpeaches() < totalCountSpeeches) { | |
} | |
System.out.println(ivanov.toString()); | |
System.out.println(petrov.toString()); | |
System.out.println(sidorov.toString()); | |
} | |
public static class Politic extends Thread { | |
private int countSounds; | |
public Politic(String name) { | |
super(name); | |
this.start(); | |
} | |
public void run() { | |
while (countSounds < totalCountSpeeches * soundsInOneSpeech) { | |
countSounds++; | |
} | |
} | |
public int getCountSpeaches() { | |
return countSounds / soundsInOneSpeech; | |
} | |
@Override | |
public String toString() { | |
return String.format("%s сказал речь %d раз", getName(), getCountSpeaches()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment