//As you sent me into the world, even so I have sent them into the world. (John 17:18) package com.javarush.task.task17.task1718; /* Ðлажка */ public class Solution { public static void main(String[] args) { Person diana = new Person("Diana"); Person igor = new Person("Igor"); diana.start(); igor.start(); } public static class Person extends Thread { //Человек public Person(String name) { super(name); } @Override public void run() { synchronized(Iron.class) { Iron iron = takeIron(); Clothes clothes = takeClothes(); ironing(iron, clothes); returnIron(); } } protected Iron takeIron() { System.out.println("Taking an Iron"); return new Iron(); } protected Iron returnIron() { System.out.println("Returning the Iron"); return new Iron(); } protected Clothes takeClothes() { return new Clothes("T-shirt"); } protected void ironing(Iron iron, Clothes clothes) { System.out.println(getName() + "'s ironing the " + clothes.name); } } public static class Iron { } //УÑÑг public static class Clothes {//Ðдежда String name; public Clothes(String name) { this.name = name; } } } /* Ðлажка Ð Ñнова бÑÑ⦠ÐоÑÑавÑÑе один synchronized, ÑÑÐ¾Ð±Ñ diana и igor гладили по оÑеÑеди, Ð²ÐµÐ´Ñ ÑÑÑг вÑего один! ÐодÑказка: иÑполÑзоваÑÑ Ð±Ð»Ð¾ÐºÐ¸ÑÐ¾Ð²ÐºÑ Ð½Ð° ÑÑовне клаÑÑа. ТÑебованиÑ: 1.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ public static клаÑÑ Clothes. 2.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ public static клаÑÑ Iron. 3.âÐлаÑÑ Solution должен ÑодеÑжаÑÑ public static клаÑÑ Person. 4.âÐлаÑÑ Person должен бÑÑÑ Ð½Ð¸ÑÑÑ. 5.âРмеÑоде run() клаÑÑа Person должен бÑÑÑ synchronized блок. 6.âSynchronized блок должен иÑполÑзоваÑÑ Ð±Ð»Ð¾ÐºÐ¸ÑÐ¾Ð²ÐºÑ Ð½Ð° ÑÑовне клаÑÑа. package com.javarush.task.task17.task1718; /* Ðлажка */ public class Solution { public static void main(String[] args) { Person diana = new Person("Diana"); Person igor = new Person("Igor"); diana.start(); igor.start(); } public static class Person extends Thread { //Человек public Person(String name) { super(name); } @Override public void run() { Iron iron = takeIron(); Clothes clothes = takeClothes(); ironing(iron, clothes); returnIron(); } protected Iron takeIron() { System.out.println("Taking an Iron"); return new Iron(); } protected Iron returnIron() { System.out.println("Returning the Iron"); return new Iron(); } protected Clothes takeClothes() { return new Clothes("T-shirt"); } protected void ironing(Iron iron, Clothes clothes) { System.out.println(getName() + "'s ironing the " + clothes.name); } } public static class Iron { } //УÑÑг public static class Clothes {//Ðдежда String name; public Clothes(String name) { this.name = name; } } } */