This assignment must use the runnable interface to implements threads that repre
ID: 3847825 • Letter: T
Question
This assignment must use the runnable interface to implements threads that represent singers The singer's singing will be simulated by displaying the each line of the songs lyrics. The project must have the following components package threadRunnablelnterfacePackage SingersClass, java SongLyricsClass, java ThreadRunnableInterfaceMainClass.iava In the SingersClass java: Implement the run method that represents each singer. In this method design a loop that the singer uses to sing the song. Create a class for the song lyrics SongLyricsClass, java Have a Sting array that has the song's lyrics. Have an accessor synchronized get method to get each line of the song array by requesting the line no Have an accessor get method to get the total number of lines in the song. You must include a couple of stanzas of your favorite song lyrics that you choose. Thread RunnablelnterfaceMainClassjava: Use spate 6 singers to test the program. In a loop, have each singer start singing. Display a message when the loop is done. Display a message when the main program is done For a reference solution to help you with the program development, see the jpeg files.Explanation / Answer
package threadRunnableInterfacePackage;
class threadRunnableInterfacePackage
{
public static void main(String args[])
{
Thread Singer1=new Thread(new SingerClass("Singer1"));
Thread Singer2=new Thread(new SingerClass("Singer2"));
Thread Singer3=new Thread(new SingerClass("Singer3"));
Thread Singer4=new Thread(new SingerClass("Singer4"));
Thread Singer5=new Thread(new SingerClass("Singer5"));
Thread Singer6=new Thread(new SingerClass("Singer6"));
Singer1.start();
Singer2.start();
Singer3.start();
Singer4.start();
Singer5.start();
Singer6.start();
System.out.println("Loop is Completed");
System.out.println("Main Program is completely executed");
}
}
class SingerClass implements Runnable
{
public String singerName;
SingerClass(String name)
{
singerName=name;
}
SongLyricsClass song= new SongLyricsClass();
public void run()
{
System.out.println("Singer is "+singerName);
for(String lyrics:song.arr)
{
System.out.print(lyrics+" ");
}
System.out.println("Singer "+singerName +"Stopped");
}
}
class SongLyricsClass
{
public String arr[]={"This","array ","contains","each line of lyrics ","of","your","desired","Song"};
public String getLyricsByLine(int lineNumber)
{
return arr[lineNumber+1];
}
public int getTotalLines()
{
return arr.length;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.