Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. 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?

  1. 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.

  1. Read through the code and highlight where superclasses are declared in yellow. Make appropriate comments on these classes. Highlight these comments in light purple.

  1. 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.

  1. 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.

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions