Advertisement
jaVer404

level16.lesson05.task03

Sep 9th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. package com.javarush.test.level16.lesson05.task03;
  2.  
  3. /* Продвижение на политических дебатах
  4. 1. Разберитесь, что делает программа.
  5. 2. Нужно сделать так, чтобы Иванов сказал больше всего речей на политических дебатах.
  6. 3. Подумай, какой метод можно вызвать у объекта ivanov, чтобы Иванов разговаривал, пока не завершится всё свободное время.
  7. */
  8.  
  9. public class Solution {
  10.     public static int totalCountSpeeches = 200;
  11.     public static int soundsInOneSpeech = 1000000;
  12.  
  13.     public static void main(String[] args) throws InterruptedException {
  14.         Politic ivanov = new Politic("Иванов");
  15.         ivanov.join();
  16.  
  17.         Politic petrov = new Politic("Петров");
  18.         Politic sidorov = new Politic("Сидоров");
  19.  
  20.  
  21.         while (ivanov.getCountSpeaches() + petrov.getCountSpeaches() + sidorov.getCountSpeaches() < totalCountSpeeches) {
  22.         }
  23.  
  24.         System.out.println(ivanov);
  25.         System.out.println(petrov);
  26.         System.out.println(sidorov);
  27.     }
  28. /*--------------------------------------------------*/
  29.     public static class Politic extends Thread {
  30.         private int countSounds;
  31.  
  32.         public Politic(String name) {
  33.             super(name);
  34.             start();
  35.         }
  36.  
  37.         public void run() {
  38.             while (countSounds < totalCountSpeeches * soundsInOneSpeech) {
  39.                 countSounds++;
  40.             }
  41.         }
  42.  
  43.         public int getCountSpeaches() {
  44.             return countSounds / soundsInOneSpeech;
  45.         }
  46.  
  47.         @Override
  48.         public String toString() {
  49.             return String.format("%s сказал речь %d раз", getName(), getCountSpeaches());
  50.         }
  51.     }
  52. /*-------------------------------------------------------*/
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement