Fill in the classes CD and CD player. See below for a sample output.

public class CDPlayerTest {

    public static void main (String [] args) {
	String beatles1 = new String(
	   "It's been a hard day's night, and I been working like a dog\n" + 
	   "It's been a hard day's night, I should be sleeping like a log\n" +
           "But when I get home to you I'll find the things that you do\n" +
           "Will make me feel alright");
	String beatles2 = new String(
	   "Ah, look at all the lonely people\n" +
	   "Ah, look at all the lonely people\n\n" +
	   "Eleanor Rigby picks up the rice in the church " + 
	   "where a wedding has been\n" + 
	   "Lives in a dream\n" + 
	   "Waits at the window, wearing the face that she keeps " + 
	   "in a jar by the door\n" + 
	   "Who is it for?");
	String beatles3 = new String(
	   "In the town where I was born\n" + 
	   "Lived a man who sailed to sea\n" + 
	   "And he told us of his life\n" + 
	   "In the land of submarines");	
		 
	String thedoors1 = new String(
	   "People are strange when you're a stranger\n" + 
	   "Faces look ugly when you're alone\n" + 
	   "Women seem wicked when you're unwanted\n" + 
	   "Streets are uneven when you're down\n");
	String thedoors2 = new String(
           "Carry me Caravan take me away\n" +
	   "Take me to Portugal, take me to Spain\n" + 
	   "Andalusia with fields full of grain\n" +
	   "I have to see you again and again\n" +
	   "Take me, Spanish Caravan\n" + 
	   "Yes, I know you can");

	String [] songs = new String[3];
	songs[0] = beatles1;
	songs[1] = beatles2;
	songs[2] = beatles3;
	CD beatles = new CD("The Beatles",songs);
	System.out.println(beatles);

	songs = new String[2];
	songs[0] = thedoors1;
	songs[1] = thedoors2;
	CD thedoors = new CD("The Doors",songs);
	System.out.println(thedoors);
	
	CDPlayer myplayer = new CDPlayer();
	myplayer.putCD(beatles);
	myplayer.play(2);
	myplayer.play(2);

	myplayer.putCD(thedoors);
	myplayer.play(2);
    }
}

class CD {
       // fill in your code
}

class CDPlayer {
       // fill in your code
}
The program should produce the following output:
C:\java>javac CDPlayerTest.java

C:\java>java CDPlayerTest
CD The Beatles with 3 songs
CD The Doors with 2 songs

It's been a hard day's night, and I been working like a dog
It's been a hard day's night, I should be sleeping like a log
But when I get home to you I'll find the things that you do
Will make me feel alright
Ah, look at all the lonely people
Ah, look at all the lonely people

Eleanor Rigby picks up the rice in the church where a wedding has been
Lives in a dream
Waits at the window, wearing the face that she keeps in a jar by the door
Who is it for?



In the town where I was born
Lived a man who sailed to sea
And he told us of his life
In the land of submarines
End of CD
EJECT CD FIRST



End of CD

C:\java>

This is an example from CSci 1211 course.

The views and opinions expressed in this page are strictly those of the page author. The contents of this page have not been reviewed or approved by the University of Minnesota.