Ejemplo n.º 1
0
 //#############################################
 //#############################################
 private static CD addCD()
 {
     int nSongs;
     CD tmpCD = new CD();
     List<Song> tmpSongList = new List<Song>();
     Console.Clear();
     cout("CD Name: ");
     tmpCD.setName(Console.ReadLine());
     cout("CD Year: ");
     tmpCD.setYear(validateNumInput(Console.ReadLine()));
     cout("Number of Songs: ");
     nSongs = validateNumInput(Console.ReadLine());
     for (int i = 1; i < nSongs+1; i++ ) {
         Song tmpSong = new Song();
         String songName, tmpString2;
         Artist tmpArtist = new Artist();
         int tmpI0;
         cout(i + ". Song:\n");
         cout("\tSongname: ");
         songName = Console.ReadLine();
         cout("\tGenre: ");
         tmpString2 = Console.ReadLine();
         cout("\tArtist: ");
         tmpArtist.setName(Console.ReadLine());
         cout("\tSonglength in seconds: ");
         tmpI0 = validateNumInput(Console.ReadLine());
         tmpSong = new Song(songName, tmpI0, tmpArtist, tmpString2);
         tmpSongList.Add(tmpSong);
     }
     tmpCD.setSongs(tmpSongList);
     return tmpCD;
 }
Ejemplo n.º 2
0
 //#############################################
 //##-------------------------------------------
 private static List<CD> formatList(String fileContent)
 {
     List<CD> tmpCDList = new List<CD>();
     string[] cds = fileContent.Split('|');
     foreach (string cd in cds) {
         CD tmpCD = new CD();
         List<Song> sList = new List<Song>();
         string[] parts = cd.Split(':');
         foreach(string part in parts){
             if(part.Contains("%y%")){
                 tmpCD.setYear(Convert.ToInt32(part.Replace("%y%", "").Replace("|", "")));
             } else if (part.Contains("%n%")) {
                 tmpCD.setName(part.Replace("%n%", "").Replace("|", ""));
             } else {
                 string[] subparts = part.Split('*');
                 Song tmpSong = new Song();
                 foreach (string subpart in subparts) {
                     Artist tmpArtist = new Artist();
                     if (subpart.Contains("%a%")) {
                         //tmpArtist.setName(subpart.Replace("%a%", "").Replace("|", ""));
                         tmpSong.setArtist(new Artist(subpart.Replace("%a%","").Replace("|","")));
                     } else if(subpart.Contains("%l%")){
                         tmpSong.setLength(validateNumInput(subpart.Replace("%l%", "").Replace("|", "")));
                     }else if(subpart.Contains("%t%")){
                         tmpSong.setName(subpart.Replace("%t%", "").Replace("|", ""));
                     }else if(subpart.Contains("%g%")){
                         tmpSong.setGenre(subpart.Replace("%g%", "").Replace("|", ""));
                     }
                 }
                 sList.Add(tmpSong);
             }
         }
         tmpCD.setSongs(sList);
         tmpCDList.Add(tmpCD);
     }
     return tmpCDList;
 }