Advertisement
oona

iPod songs

Feb 26th, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. public class durationOfMusic {
  2.  
  3.     public static void main(String[] args) {
  4.         // TODO Auto-generated method stub
  5.  
  6.         String song[] = {"Mamma Mia", "Tiger", "YMCA", "Pour Que Tu M'aimes Encore", "My Heart Will Go On", "I'm Gonna Be (500 Miles)", "I'm Alive", "As Good As New", "Hasta Mi Final", "Roar"}; //10 songs in the iPod so far
  7.         String artist[] = {"Abba", "Abba", "Village People", "Il Divo", "Celine Dion", "The Proclaimers", "Celine Dion", "Abba", "Il Divo", "Katy Perry"}; //best artists so far
  8.         int durationSec[] = {211, 175, 287, 235, 281, 219, 211, 206, 216, 224}; //the number of seconds each song takes
  9.         int total = 0; //to hold the total number of seconds
  10.        
  11.         //the total duration of the whole iPod
  12.         for(int i = 0; i<durationSec.length; i++)
  13.         {
  14.             total = total + durationSec[i];
  15.             System.out.println("Your iPod contains music lasting for " + total + " sec. in total");
  16.         }
  17.        
  18.         //now to see which song takes the longest
  19.         //the songs are sorted in descending order
  20.         for(int i = 0; i<durationSec.length; i++)
  21.         {
  22.             for(int j = 1; j<(durationSec.length-1); j++)
  23.             {
  24.                 if(durationSec[j]>durationSec[j-1])
  25.                 {
  26.                     int temp1 = durationSec[j];
  27.                     durationSec[j] = durationSec[j-1];
  28.                     durationSec[j-1] = temp1;
  29.                    
  30.                     String temp2 = song[j];
  31.                     song[j] = song[j-1];
  32.                     song[j-1] = temp2;
  33.                    
  34.                     String temp3 = artist[j];
  35.                     artist[j] = artist[j-1];
  36.                     artist[j-1] = temp3;
  37.                 }
  38.             }
  39.         }
  40.         for(int i = 0; i<durationSec.length; i++)
  41.             System.out.println(song[i] + " by " + artist[i] + ", " + durationSec[i] + " sec.");
  42.     }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement