Question
Hi there, This question is regarding a java programming assignment. In this assignment, an example code is provided. The example code has to be read
Hi there,
This question is regarding a java programming assignment. In this assignment, an example code is provided. The example code has to be read through and certain parts of it have to be highlighted according to the instructions. For example, the superclass, subclasses, polymorphism, etc has to be identified. The example code then has to be fixed so that it is functioning again.
-
Copy and paste the following code from Playlist into Java. Does the program function properly? If not, what kind of error are you getting? When it function properly what does the program do?
-
For each method make a comment that states the pre and post conditions as well as what it does. Highlight these comments in light blue.
-
Read through the code and highlight where superclasses are declared in yellow. Make appropriate comments on these classes. Highlight these comments in light purple.
-
Read through the code and highlight where subclasses are declared in light green. Make appropriate comments on these classes. Highlight these comments in light purple.
-
Read through the code and highlight any examples of polymorphism in light red.. Comment on what has been changed. Highlight these comments in light purple.
-
Fix the code so that the program runs properly. Create one more type of music and include two instances of this music type for the Playlist. Submit your corrected version of this program.
Example Code:
public class Playlist
{
public static void main( String[] args )
{
RockAlbum metal = new RockAlbum( "My Head is an Animal", "Of Monsters and Men", 2011);
rock.playlist = "Little Talks, Dirty Paws, Mountain Sound";
rock.play();
PopAlbum pop = new PopAlbum( "The 20/20 Experience", "Justin Timberlake", 2013);
pop.playlist = "Mirrors, Suit & Tie, Tunnel Vision";
pop.play();
RockAlbum metal = new RockAlbum( "Concrete and Gold", "Foo Fighters", 2017);
rock.playlist = "Run, The Sky is a Neighborhood, The Line";
rock.play();
PopAlbum pop = new PopAlbum( "Trench", "Twenty-One Pilots", 2018);
pop.playlist = "They Hype, My Blood, The Hype";
pop.play();
KidsSongs ks = new KidsSongs( "Baby Shark", "Pink Fong", 2017);
ks.play();
}
}
abstract class Album
{
String name;
String author;
int year;
String playlist;
Album( String name, String author, int year )
{
this.name = name;
this.author = author;
this.year = year;
}
String getPlaylist()
{
return "This bit is useless anyway " + this.playlist;
}
void play()
{
System.out.println( this.getPlaylist() );
}
}
class KidsSongs extends Album
{
String choirName;
public KidsSongs( String name, String author, int year )
{
super( name, author, year );
}
@Override
String getPlaylist()
{
return "Kids songs";
}
}
class PopAlbum extends Album
{
public PopAlbum( String name, String author, int year )
{
super( name, author, year );
}
String getPlaylist()
{
return this.playlist;
}
@Override
void play()
{
System.out.println( "Playing Pop" );
super.play();
}
}
class RockAlbum extends Album
{
public RockAlbum( String name, String author, int year )
{
super( name, author, year );
}
@Override
String getPlaylist()
{
return this.playlist;
}
@Override
void play()
{
System.out.println( "Playing alternative rock.." );
super.play();
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started