All pastes #2109440 Raw Edit

Untitled

public java v1 · immutable
#2109440 ·published 2012-02-03 17:11 UTC
rendered paste body
itunesimport cs1.Keyboard;public class iTunes {	public static void main (String[] args){		MP3Collection music= new MP3Collection();		int menu=0;		while (menu!=3){		System.out.println("Enter 1 to Enter A Song, Enter 2 To View Collection,\r Enter 3 To Quit");			menu=Keyboard.readInt();		if (menu==1){		String title="",artist="";		int duration=0;		System.out.println("Enter Song Title");		title=Keyboard.readString();		System.out.println("Enter Song Artist");		artist=Keyboard.readString();		System.out.println("Enter Song Minutes");		duration+=(Keyboard.readInt()*60);		System.out.println("Enter Song Seconds");		duration+=(Keyboard.readInt());		music.addMP3(title, artist, duration);}		else if (menu==2){			System.out.println(music);}}}}public class MP3Collection {	private MP3[] collection;	   private int count;  	   private int totalDuration;	   //-----------------------------------------------------------------	   //  Creates an initially empty collection.	   //-----------------------------------------------------------------	   public MP3Collection ()	   {	      collection = new MP3[100];	      count = 0;	      totalDuration = 0;	   }	   //-----------------------------------------------------------------	   //  Adds a CD to the collection, increasing the size of the	   //  collection if necessary.	   //-----------------------------------------------------------------	   public void addMP3 (String title, String artist,	                      int duration)	   {	      if (count == collection.length)	         increaseSize();	         collection[count] = new MP3 (title, artist,duration );	         totalDuration += duration;	         count++;	   }	   //-----------------------------------------------------------------	   //  Returns a report describing the CD collection.	   //-----------------------------------------------------------------	   public String toString()	   {	     double avgDuration=((double)totalDuration/count);	     int avg= (int) Math.round(avgDuration); 	      String report = "******************************************\n";	      report += "My MP3 Collection\n\n";	      report += "Number of MP3s: " + count + "\n";	      report += "Total Duration MM:SS : " + (Time.convert(totalDuration)) + "\n";	      report += "Average Duration MM:SS : " +(Time.convert(avg));	      report += "\n\nMP3 List:\n\n";	      	      for (int MP3 = 0; MP3 < count; MP3++)	         report += collection[MP3].toString() + "\n";	      return report;	   }	   //-----------------------------------------------------------------	   //  Doubles the size of the collection by creating a larger array	   //  and copying the existing collection into it.	   //-----------------------------------------------------------------	   private void increaseSize ()	   {	      MP3[] temp = new MP3[collection.length * 2];	      for (int MP3 = 0; MP3 < collection.length; MP3++)	         temp[MP3] = collection[MP3];	      collection = temp;	   }}	//********************************************************************//  CD.java       Author: Lewis/Loftus/Cocking////  Represents a compact disc.//********************************************************************public class MP3 {   private String title, artist;   private int time;      //-----------------------------------------------------------------   //  Creates a new CD with the specified information.   //-----------------------------------------------------------------   public MP3 (String name, String singer, int duration)   {      title = name;      artist = singer;      time = duration;         }   //-----------------------------------------------------------------   //  Returns a description of this CD.   //-----------------------------------------------------------------   public String toString()      {        String description;      description = "Time in MM:SS="+ (Time.convert(time)) + "\t" ;      description +="Title: "+ title + "\t Artist: " + artist;      return description;   }}public class Time {	public static String convert (int time){	int minutes=(time/60);	   int seconds=(time-((time/60)*60));	   String strSeconds;	   if (seconds<10)		   strSeconds=((String)"0"+seconds);	   else		   strSeconds=((String)""+seconds);		   return (minutes+":"+strSeconds); }}