An iTune entry in music library is a descriptor that summarizes information abou
ID: 663219 • Letter: A
Question
An iTune entry in music library is a descriptor that summarizes information about the tune that it describes. (It is not the actual tune, which is contained in a large music data file.)
This application will start you on your way to building your very own music library. Using descriptors to identify each iTune entry, you will be able to build your repository of music favorites. Not only that, as your library grows you be able to find your iTune entry thanks to the organized filing system that you are about to explore.
For each iTune entry in your own music library file there are between 20 and 50 fields
Explanation / Answer
/*The class iTunes that sets the title, artist name ,bit rate and
* play time of a song.And also check for invald type of arguments are passed
to the setter metods of iTunes class
* */
//iTunes.java
public class iTunes
{
//default values to set for private members of the class iTunes
public static int MIN_BITRATE = 64;
public static int MAX_BITRATE = 705;
public static int MIN_STR_LENGTH = 1;
public static int MAX_STR_LENGTH = 80;
public static int MIN_PLAY_TIME = 0;
public static int MAX_PLAY_TIME = 1000*60*60;
public static int DEFAULT_BITRATE = 64;
public static int DEFAULT_PLAY_TIME = 1;
public static String DEFAULT_STRING = "(undefined)";
//private members of the class iTunes
private String name;
private String artist;
private int bitrate;
private int total_time;
//Default constructor to set default values
public iTunes()
{
//set default values
name=DEFAULT_STRING;
artist=DEFAULT_STRING;
bitrate=DEFAULT_BITRATE;
total_time=DEFAULT_PLAY_TIME;
}
/*Mutator methods of private members of iTunes class
Method to set the title of the song
Checking if lenght of the artist is valid
if not return false
*/
public boolean setName(String name)
{
boolean valid=true;
if(name.length()>=1 && name.length()<=80)
this.name=name;
else
valid=false;
return valid;
}
/*Method to set the artist name
Checking if lenght of the artist is valid
if not return false
*/
public boolean setArtist(String artist)
{
boolean valid=true;
//Check for valid lenght of the artist string
if(name.length()>=1 && name.length()<=80)
this.artist=artist;
else
valid=false;
return valid;
}
//Method to set the bitrate
/*Checking if bit rate is valid
if not return false */
public boolean setBitrate(int bitrate)
{
boolean valid=true;
//check if the bitrate is valid or not
if(bitrate>=MIN_BITRATE && bitrate<=MAX_BITRATE)
this.bitrate=bitrate;
else
valid=false;
return valid;
}
//Method to set the play time
/*Checking if play time is valid
if not return false */
public boolean setPlayTime(int total_time)
{
boolean valid=true;
//Check for valid play time
if(total_time>MIN_PLAY_TIME && total_time<=MAX_PLAY_TIME)
this.total_time=total_time;
else
valid=false;
return valid;
}
//Accessor methods of private members of iTunes class
//Return title of the song
public String getName()
{
return name;
}
//Return artist of the song
public String getArtist()
{
return artist;
}
//Return bit rate of the song
public int getBitrate()
{
return bitrate;
}
//Return play time of the song
public int getPlayTime()
{
return total_time;
}
/*Override toString that displays the string represenation
of the iTunes object */
@Override
public String toString()
{
return "Title:"+name+"/Artist: "+artist
+"/Playing Time: "+total_time/60+" Minutes "+
(total_time%60)+" seconds"
+"/ Bit Rate: "+bitrate+"K";
}
//Display the string returned by toString method
public void display()
{
System.out.println(toString());
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
Driver program to test the class iTunes
/*The driver program that instantiates the objects of iTunes class
* dynamically set values of name,artist,bit rate and play time and
* print the appropriate error messages while setting values.
* Otherwise print song description.
* */
//iTunesDriver.java
public class iTunesDriver
{
public static void main(String[] args)
{
//Instantiate iTunes first object
iTunes song1=new iTunes();
System.out.println("song1");
/* Checking if return values from the setter methods of the iTunes
class are false then print the appropriate message to indicate
the invalid arguments are passed to iTunes object*/
//call setter methods to ste name,artist,palytime ,bitrate
if(!song1.setName("You were Never Mind"))
System.out.println("Invaid title");
if(!song1.setArtist("Janiva Magness"))
System.out.println("Invaid artist");
if(!song1.setPlayTime(276))
System.out.println("Invaid play time");
if(!song1.setBitrate(128))
System.out.println("Invaid bit rate");
System.out.println("song1 Details");
//call display method to print string description of song1 object
song1.display();
//Instantiate iTunes second object
iTunes song2=new iTunes();
System.out.println("song2");
//call setter methods to set name,artist,palytime ,bitrate
if(!song2.setName("Waka Waka"))
System.out.println("Invaid title");
if(!song2.setArtist("Shakerara"))
System.out.println("Invaid artist");
if(!song2.setPlayTime(0))
System.out.println("Invaid play time");
if(!song2.setBitrate(64))
System.out.println("Invaid bit rate");
System.out.println("song2 Details");
//call display method to print string description of song1 object
song2.display();
//Instantiate iTunes first object
iTunes song3=new iTunes();
System.out.println("song3");
//call setter methods to ste name,artist,palytime ,bitrate
if(!song3.setName("Hobo Blues"))
System.out.println("Invaid title");
if(!song3.setArtist("John Lee Hooker"))
System.out.println("Invaid artist");
if(!song3.setPlayTime(452))
System.out.println("Invaid play time");
if(!song3.setBitrate(1024))
System.out.println("Invaid bit rate");
System.out.println("song3 Details");
//call display method to print string description of song1 object
song3.display();
}
}
------------------------------------------------------------------------------------------------------------------------------------------------
sample output:
song1
song1 Details
Title:You were Never Mind/Artist: Janiva Magness/Playing Time: 4 Minutes 36 seconds/ Bit Rate: 128K
song2
Invaid play time
song2 Details
Title:Waka Waka/Artist: Shakerara/Playing Time: 0 Minutes 1 seconds/ Bit Rate: 64K
song3
Invaid bit rate
song3 Details
Title:Hobo Blues/Artist: John Lee Hooker/Playing Time: 7 Minutes 32 seconds/ Bit Rate: 64K
Hope this helps you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.