//But all these things will they do to you for my name's sake, because they don't know him who sent me. (John 15:21) package com.javarush.task.task16.task1605; import java.util.Date; * ÐоговоÑим о мÑзÑке * public class Solution { public static int delay = 1000; public static void main(String[] args) { Thread violin = new Thread(new Violin("Player")); violin.start(); } public static void sleepNSeconds(int n) { try { Thread.sleep(n * delay); } catch (InterruptedException e) { e.printStackTrace(); } } public interface MusicalInstrument extends Runnable { Date startPlaying(); Date stopPlaying(); } public static class Violin implements MusicalInstrument { private String owner; public void run() { Date start = startPlaying(); sleepNSeconds(1); Date end = stopPlaying(); System.out.println("Playing " + (end.getTime() - start.getTime()) + " ms"); } public Violin(String owner) { this.owner = owner; } public Date startPlaying() { System.out.println(this.owner + " starts playing"); return new Date(); } public Date stopPlaying() { System.out.println(this.owner + " stops playing"); return new Date(); } } } /* ÐоговоÑим о мÑзÑке 1. Ðзмени клаÑÑ Violin Ñак, ÑÑоб он ÑÑал ÑаÑком Ð´Ð»Ñ Ð½Ð¸Ñи. ÐÑполÑзÑй инÑеÑÑÐµÐ¹Ñ MusicalInstrument 2. РеализÑй Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ñй меÑод в ниÑи Violin. РеализаÑÐ¸Ñ Ð´Ð¾Ð»Ð¶Ð½Ð° бÑÑÑ ÑледÑÑÑей: 2.1. СÑиÑай вÑÐµÐ¼Ñ Ð½Ð°Ñала игÑÑ â меÑод startPlaying(). 2.2. Ðодожди 1 ÑекÑÐ½Ð´Ñ â меÑод sleepNSeconds(int n), где n â колиÑеÑÑво ÑекÑнд. 2.3. СÑиÑай вÑÐµÐ¼Ñ Ð¾ÐºÐ¾Ð½ÑÐ°Ð½Ð¸Ñ Ð¸Ð³ÑÑ â меÑод stopPlaying(). 2.4. ÐÑведи на конÑÐ¾Ð»Ñ Ð¿ÑодолжиÑелÑноÑÑÑ Ð¸Ð³ÑÑ Ð² миллиÑекÑÐ½Ð´Ð°Ñ . ÐÑÐ¸Ð¼ÐµÑ Â«Playing 1002 ms«. ТÑебованиÑ: 1.âÐлаÑÑ Violin не должен бÑÑÑ ÑнаÑледован Ð¾Ñ ÐºÐ°ÐºÐ¾Ð³Ð¾-либо дополниÑелÑного клаÑÑа. 2.âÐлаÑÑ Violin должен ÑеализовÑваÑÑ Ð¸Ð½ÑеÑÑÐµÐ¹Ñ MusicalInstrument. 3.âÐеÑод run клаÑÑа Violin должен вÑзÑваÑÑ Ð¼ÐµÑод startPlaying. 4.âÐеÑод run клаÑÑа Violin должен вÑзÑваÑÑ Ð¼ÐµÑод sleepNSeconds Ñ Ð¿Ð°ÑамеÑÑом 1 ÑекÑнда. 5.âÐеÑод run клаÑÑа Violin должен вÑзÑваÑÑ Ð¼ÐµÑод stopPlaying. 6.âÐеÑод run клаÑÑа Violin должен вÑводиÑÑ Ð½Ð° конÑÐ¾Ð»Ñ Ð¿ÑодолжиÑелÑноÑÑÑ Ð¸Ð³ÑÑ Ð² миллиÑекÑÐ½Ð´Ð°Ñ . ÐÑполÑзÑй ÑоÑÐ¼Ð°Ñ Ð¸Ð· пÑимеÑа. package com.javarush.task.task16.task1605; import java.util.Date; * ÐоговоÑим о мÑзÑке * public class Solution { public static int delay = 1000; public static void main(String[] args) { Thread violin = new Thread(new Violin("Player")); violin.start(); } public static void sleepNSeconds(int n) { try { Thread.sleep(n * delay); } catch (InterruptedException e) { e.printStackTrace(); } } public interface MusicalInstrument extends Runnable { Date startPlaying(); Date stopPlaying(); } public static class Violin { private String owner; public Violin(String owner) { this.owner = owner; } public Date startPlaying() { System.out.println(this.owner + " starts playing"); return new Date(); } public Date stopPlaying() { System.out.println(this.owner + " stops playing"); return new Date(); } } } */