// If I hadn't done among them the works which no one else did, they wouldn't have had sin. //But now have they seen and also hated both me and my Father. (John 15:24) package com.javarush.task.task16.task1608; /* ÐÑодвижение на полиÑиÑеÑÐºÐ¸Ñ Ð´ÐµÐ±Ð°ÑÐ°Ñ */ public class Solution { public static int totalCountSpeeches = 200; public static int soundsInOneSpeech = 1000000; public static void main(String[] args) throws InterruptedException { Politician ivanov = new Politician("Ðванов"); ivanov.join(); Politician petrov = new Politician("ÐеÑÑов"); Politician sidorov = new Politician("СидоÑов"); while (ivanov.getCountSpeeches() + petrov.getCountSpeeches() + sidorov.getCountSpeeches() < totalCountSpeeches) { } System.out.println(ivanov); System.out.println(petrov); System.out.println(sidorov); } public static class Politician extends Thread { private volatile int countSounds; public Politician(String name) { super(name); start(); } public void run() { while (countSounds < totalCountSpeeches * soundsInOneSpeech) { countSounds++; } } public int getCountSpeeches() { return countSounds / soundsInOneSpeech; } @Override public String toString() { return String.format("%s Ñказал ÑеÑÑ %d Ñаз", getName(), getCountSpeeches()); } } } /* ÐÑодвижение на полиÑиÑеÑÐºÐ¸Ñ Ð´ÐµÐ±Ð°ÑÐ°Ñ 1. РазбеÑиÑÑ, ÑÑо Ð´ÐµÐ»Ð°ÐµÑ Ð¿ÑогÑамма. 2. ÐÑжно ÑделаÑÑ Ñак, ÑÑÐ¾Ð±Ñ Ðванов Ñказал болÑÑе вÑего ÑеÑей на полиÑиÑеÑÐºÐ¸Ñ Ð´ÐµÐ±Ð°ÑÐ°Ñ . 3. ÐодÑмай, какой меÑод можно вÑзваÑÑ Ñ Ð¾Ð±ÑекÑа ivanov, ÑÑÐ¾Ð±Ñ Ðванов ÑазговаÑивал, пока не завеÑÑиÑÑÑ Ð²ÑÑ Ñвободное вÑемÑ. ТÑебованиÑ: 1.âÐÑзови меÑод join Ñ Ð½Ñжного обÑекÑа. 2.âÐеÑод toString клаÑÑа полиÑик Politician должен вÑводиÑÑ ÑколÑко ÑеÑей Ñказал полиÑик, напÑимеÑ: "Ðванов Ñказал ÑеÑÑ 35 Ñаз". 3.âÐÑогÑамма должна ÑоздаваÑÑ 3 обÑекÑа Ñипа Politician. 4.âÐеÑодÑ, коÑоÑÑе оÑвеÑаÑÑ Ð·Ð° вÑвод в конÑолÑ, не изменÑÑÑ. 5.âÐÑвод пÑогÑÐ°Ð¼Ð¼Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ ÑвидеÑелÑÑÑвоваÑÑ Ð¾ Ñом, ÑÑо Ðванов Ñказал болÑÑе вÑего ÑеÑей на полиÑиÑеÑÐºÐ¸Ñ Ð´ÐµÐ±Ð°ÑÐ°Ñ . package com.javarush.task.task16.task1608; * ÐÑодвижение на полиÑиÑеÑÐºÐ¸Ñ Ð´ÐµÐ±Ð°ÑÐ°Ñ * public class Solution { public static int totalCountSpeeches = 200; public static int soundsInOneSpeech = 1000000; public static void main(String[] args) throws InterruptedException { Politician ivanov = new Politician("Ðванов"); Politician petrov = new Politician("ÐеÑÑов"); Politician sidorov = new Politician("СидоÑов"); while (ivanov.getCountSpeeches() + petrov.getCountSpeeches() + sidorov.getCountSpeeches() < totalCountSpeeches) { } System.out.println(ivanov); System.out.println(petrov); System.out.println(sidorov); } public static class Politician extends Thread { private volatile int countSounds; public Politician(String name) { super(name); start(); } public void run() { while (countSounds < totalCountSpeeches * soundsInOneSpeech) { countSounds++; } } public int getCountSpeeches() { return countSounds / soundsInOneSpeech; } @Override public String toString() { return String.format("%s Ñказал ÑеÑÑ %d Ñаз", getName(), getCountSpeeches()); } } } */