Introduction
In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist.
The Base Class, Derived Class and Test Client
Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need to "upload" these into zyLabsfor grading. There will be two class files and a single client file, details of which are described below.
Building the SongBase Class:
The members of the SongBase class are listed in a diagram below known as a Unified Modeling Language (UML) diagram. You must use the same field names and method names as listed in the diagram. This will insure that the included tests for the program will work for your implemented class.
How to read the UML diagram below This is a
simplified version of a class diagram known as a "UML diagram" or
"Unified Modeling Language diagram". These types of diagrams are
commonly used during the software engineering design process when
programmers are first building classes and client files. They are
programming language independent. The following are some
descriptions of the parts of a UML diagram:
|
Class Name |
SongBase |
Instance Variables (fields) |
- title: String - artist: String - genre : int |
Constructors |
+ SongBase() + SongBase(String title, String artist, int genre) |
Instance Methods |
+ setTitle(String title) : void + setArtist(String artist) : void + setGenre(int genre) : void + getTitle() : String + getArtist() : String + getGenre() : int + getGenreName() : String + toString() : String + equals(Object other) : boolean |
Decomposition Information for SongBase Class
You may add additional helper methods for a class if you wish, but the methods from the UML, described in more detail below must be included since they will be unit tested.
TIP: Build the Base Class first - You should build the base class first and devise a client that can test the base class much like we did in lecture. Once you feel pretty good about your base class, you can begin developing the PlaylistDerived Class next. You do NOT want to develop the entire application at once unless you have a strong desire to spend several days debugging your program.
Extending the Base Class with the PlaylistDerived Class:
The members of the PlaylistDerived class are listed below in the UML diagram. You must use the same field names and method names as listed in the diagram. This will insure that the included tests for the program will work for your implemented class.
Class Name |
PlaylistDerived |
Constants and Instance Variables (fields) |
- MAXSIZE : int constant (max size of playlist is 8) - playlist (an array of song objects) : SongBase[MAXSIZE] - count (count of songs in the playlist): int |
Constructors |
+ PlaylistDerived() |
Instance Methods |
+ getCount() : int + addSong(String title, String artist, int genre) : int + removeSong(String title, String artist, int genre) : int + moveSongsUp(int position) : void + findSong(SongBase songtoFind) : int + customPlayList(String artist) : String + customPlayList(int genre) : String + toString() : String |
Decomposition Information for PlayListDerived Class
You may add additional helper methods for a class if you wish, but the methods from the UML, described in more detail below must be included since they will be unit tested.
TIP: Build this class after the base class - You should build the PlayList class after building the base class and devise a client that can test the PlayList class much like we did in lecture. Once you feel good about your PlayList class, you can start developing the client application.
Building the Client Test Program:
The client program you develop is simply going to be a test driver. In other words, it should thoroughly test your base and derived class. Since you've not had prior experience doing this, we are providing the final test client for you. You may add lines, comment out lines or modify this as you wish to assist you with any testing you perform during your development process and prior to submitting to zyBooks. Of course, zyBooks will also test almost every method to ensure that it follows the specs appropriately.
Sample Run (using the provided test client):
SongBase.java
public class SongBase {
private String title, artist;
private int genre;
public SongBase()
{
this.title = "";
this.artist = "";
this.genre = -1;
}
public SongBase(String title, String artist, int genre)
{
this.title = title;
this.artist = artist;
// if genre is not anyone of the following: 0, 1, 2, by default, it
sets the genre to 0
if(genre != 0 && genre != 1 && genre != 2)
this.genre = 0;
else
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public int getGenre() {
return genre;
}
public void setGenre(int genre) {
this.genre = genre;
}
public String getGenreName()
{
String res;
if(this.genre == -1)
res = "";
else
{
switch(this.genre)
{
case 0:
res = "Holiday";
break;
case 1:
res = "Dance";
break;
case 2:
res = "Romance";
break;
default:
res = "";
}
}
return res;
}
@Override
public String toString()
{
return("Title: " + this.title + "\n"
+ "Artist: " + this.artist + "\n"
+ "Genre: " + getGenreName());
}
@Override
public boolean equals(Object other)
{
if(other instanceof SongBase)
return (this.title.equalsIgnoreCase(((SongBase)
other).getTitle())
&& this.artist.equalsIgnoreCase(((SongBase)
other).getArtist())
&& getGenreName().equalsIgnoreCase(((SongBase)
other).getGenreName()));
else
return false;
}
}
PlaylistDerived.java
public class PlaylistDerived extends SongBase{
private static final int MAXSIZE = 8;
private SongBase playlist[] = new SongBase[MAXSIZE];
private int count;
public PlaylistDerived()
{
this.count = 0;
}
public int getCount(){ return this.count; }
public int addSong(String title, String artist, int genre)
{
if(count == MAXSIZE)
throw new ArrayIndexOutOfBoundsException("Cannot add: " +
title
+ " Maximum playlist size is " + MAXSIZE + ".");
SongBase song = new SongBase(title, artist, genre);
if(this.count == 0)
{
this.playlist[count] = song;
this.count += 1;
return 0;
}
else
{
if(findSong(song) == -1) // not duplicate
{
this.playlist[count] = song;
this.count += 1;
return 0;
}
else
return -1;
}
}
public int removeSong(String title, String artist, int genre)
{
SongBase song = new SongBase(title, artist, genre);
if(findSong(song) != -1)
{
int position = findSong(song);
moveSongsUp(position);
this.count -= 1;
return 0;
}
else
return -1;
}
public String customPlaylist(String artist)
{
String res = "";
for(int i = 0; i < count; i++)
{
if(this.playlist[i].getArtist().equalsIgnoreCase(artist))
res += this.playlist[i].toString() +
"\n--------------------\n";
}
if(res.equals(""))
return "No songs by this artist found.";
else
return res;
}
public String customPlaylist(int genre)
{
String res = "";
for(int i = 0; i < count; i++)
{
if(this.playlist[i].getGenre() == genre)
res += this.playlist[i].toString() +
"\n--------------------\n";
}
if(res.equals(""))
return "No songs in this genre found.";
else
return res;
}
public int findSong(SongBase songToFind)
{
int index = -1;
if(this.count == 0)
index = -1;
else
{
for(int i = 0; i < this.count; i++)
{
if(this.playlist[i].equals(songToFind))
{
index = i;
break;
}
}
}
return index;
}
public void moveSongsUp(int position)
{
for(int i = position; i < count - 1; i++)
{
this.playlist[i] = this.playlist[i + 1];
}
}
@Override
public String toString()
{
String res = "";
if(count == 0)
res = "Playlist is empty\n";
else
{
res = "My Playlist (count of songs = " + getCount() +
")\n\n";
for(int i = 0; i < count; i++)
{
if(i == count - 1)
res += (i + 1) + ". " + this.playlist[i].toString() + "\n";
else
res += (i + 1) + ". " + this.playlist[i].toString() + "\n\n";
}
}
return res;
}
}
SongsTester.java (Client?Driver class)
public class SongsTester {
public static void main(String[] args)
{
System.out.println("***** Testing creating new playlist
*****");
PlaylistDerived playlist = new PlaylistDerived();
System.out.println(playlist);
System.out.println("\n***** Testing adding 6 songs *****");
playlist.addSong("White Christmas", "Bing Crosby", 0);
playlist.addSong("White Christmas", "Bedha Skolar", 0);
playlist.addSong("Jingle Java Christmas", "NaDHA Skolar", 0);
playlist.addSong("All I Want For Christmas is For Nadha To Pass",
"The Skolar Family", 0);
playlist.addSong("Be My Java Bae", "NAdha Skolar", 1);
playlist.addSong("Sad Sitch", "Stellar Skolar", 0);
System.out.println(playlist);
System.out.println("\n***** Testing adding duplicate songs
*****");
if(playlist.addSong("Be My Java Bae", "nadha SKOLAR", 0) ==
-1)
System.out.println("ERROR: Duplicate song Be My Java Bae (genre 0)
not added");
else
System.out.println("SUCCESS: Song Be My Java Bae (genre 0)
successfully added");
if(playlist.addSong("Be My Java Bae", "nadha SKOLAR", 0) ==
-1)
System.out.println("ERROR: Duplicate song Be My Java Bae (genre 0)
not added");
else
System.out.println("SUCCESS: Song Be My Java Bae (genre 0)
successfully added");
if(playlist.addSong("Jingle Java Christmas", "NaDHA Skolar", 0) ==
-1)
System.out.println("ERROR: Duplicate song Jingle Java Christamas
(genre 0) not added");
else
System.out.println("SUCCESS: Song Jingle Java Christamas (genre 0)
successfully added");
System.out.println("\n" + playlist);
System.out.println("\n***** Testing overflowing the playlist
*****");
playlist.addSong("Jingly Java Christmas", "NADHA SKOLAR", 1);
playlist.addSong("AddMe4", "BEDHA SKOLLAR", 0);
System.out.println(playlist);
}
}
******************************************************************* SCREENSHOT ****************************************************
Introduction In this final programming exercise, you'll get a chance to put together many of the...
Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...
(1) Create two files to submit: Song.java - Class definition MainClass.java - Contains main() method (2) Build the Song class in Song.java with the following specifications: Private fields String songTitle String songArtist int secDuration Initialize String fields to "Not defined" and numeric to 0. Create overloaded constructor to allow passing of 1 argument (title), 2 (title, artist) and 3 arguments (title, artist, duration). Create public member method printSongInfo () with output formatted as below: Title: Born in the USA Artist:...
java With the incredible royalties on your Jukebox-management code, to become a DJ. You realize that you can adapt the Jukebox code to create some sophistica software for your new career. Consider the slightly simplified versio As a DJ, you are mainly interested in the BPM (beats per minute) and rating of the songs. you decide to indulge your dream n of the book's Song class below. public class Song private String title private String artist; private int rating private...
JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...
Create two classes. Song. Should include the name of the song and the artist Playlist. Should include a list of song objects from the above class, a title for the list and a description of the list. Specific method requirements below. Functionality You should be able to print both a song and a playlist. Formatting should follow the below examples EXACTLY. I should be able to print a so11ng or a playlist by calling the standard python print function. Format...
Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...
Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...
I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...
public class Song { private String title; private String artist; private int duration; public Song() { this("", "", 0, 0); } public Song(String t, String a, int m, int s) { title = t; artist = a; duration = m * 60 + s; } public String getTitle() { return title; } public String getArtist() { return artist; } public int getDuration() { return duration; } public int getMinutes() { return duration / 60; } public int getSeconds() { return...