user2224223
user2224223

Reputation: 45

C# How to get data into an array within an array

I'm trying to build a CD collection program in C# that can

  1. Create a new album (ie, add a new entry in your album database)
  2. Change or delete an existing album in your album database
  3. Enter the details of a piece of music (title, artist, genre, and the length of the music) into an album
  4. Change or delete the details of an existing music in an album
  5. List the details of all music in a given album
  6. List all music by a given artist
  7. List all music in your database. Your program must allow the user to choose the order of listing: by album, by artist, by genre, or by title.

I'm stuck on the 3rd bit, adding details to each album, so far i have this, i figure when i get this right, the rest of the details will be easy to add

public bool AddSong(string songName)
    {
        for (int i = 0; i < MAX_MUSIC; i++)
        {
            string c = albumName;                   // This compares the album name given by user
            string e = myMusic[i].getAlName;        // to the album name in the myMusic array
            int d = c.CompareTo(e);                 //
            if (d == 0)
            {
                int index = -1;
                for (int j = 0; j < MAX_SONG; j++)
                {
                    if (Songs[i] == null)
                    {
                        index = i;
                        break;
                    }
                }
                if (index != -1)
                {
                    Songs[index] = songName;
                    ++totalSongs;
                    return true;
                }
            }
        }


        return false;

    }

any help to give me direction would be much appreciated.

EDIT: This is homework, I'm an external student and my lecturer as nice as he is, doesn't speak english very well, I don't expect freebies. Just direction on approach and maybe an odd hint ;)

EDIT2: My code is very large so i dont think it is appropriated to post such large amounts of code, i can though provide a link to the classes

musicDB.cs

music.cs

Form1.cs

Upvotes: 0

Views: 260

Answers (2)

Carra
Carra

Reputation: 17964

           for (int j = 0; j < MAX_SONG; j++)
            {
                if (Songs[i] == null)
                {
                    index = i;
                    break;
                }
            }

You're looping through j but you're not using j in your for loop. So you're really doing the same thing MAX_SONG times.

Upvotes: 1

Davin Tryon
Davin Tryon

Reputation: 67296

if (index != -1)
{
     Songs[index] = songName;
     ++totalSongs;
     return true;
}

This is the section you need to focus on now.

Ask yourself:

  1. How to create a new Song class (initialize)?
  2. How to set properties on the Song class?
  3. Finally, how to apply the Song to the correct position in the array?

Upvotes: 1

Related Questions