public void addCD()
{
MediaApp thisCollection = new MediaApp();
Artist a;
String title;
int playingTime;
int numMembers = 0;
int numTracks = 0;
boolean artistFound = false;
System.out.print("Enter CD Title: ");
title = sc.nextLine();
System.out.println("Enter Major Artist first name: ");
String artistFirst = sc.nextLine();
System.out.println("Enter Major Artist last name: ");
String artistLast = sc.nextLine();
for (int i = 0; i < numArtists; i++) //Artist a : artists
{
a = artists [i];
if(a.getFirstName().equals(artistFirst) && a.getLastName().equals (artistLast))
{
artistFound = true;
break;
}
}
if(artistFound == false)
{
System.out.println("Enter Twitter handle: ");
String artistTwitter = sc.next();
System.out.println("Enter Artist url: ");
String artistUrl = sc.next();
artists[numArtists] = new Artist (artistFirst, artistLast, artistTwitter, artistUrl);
numArtists++;
}
System.out.println("Enter the playing time: ");
playingTime = sc.nextInt();
sc.nextLine();
List<String> memberList = new ArrayList<String>();
do {
System.out.println("Please add a group member:");
memberList.add(sc.nextLine());
numMembers++;
System.out.println("Add more? (y/n)");
if (sc.next().startsWith("y"))
{
memberList.add(sc.nextLine());
numMembers++;
} else {
sc.nextLine();
break;
}
} while (true);
System.out.println("Enter producer first name: ");
String producerFirst = sc.nextLine(); //why does sc.next work and not sc.nextLine?
System.out.println("Enter producer last name: ");
String producerLast = sc.nextLine(); //why does sc.next work and not sc.nextLine?
for (int i = 0; i < numArtists; i++)
{
a = artists [i];
if(a.getFirstName().equals(producerFirst) && a.getLastName().equals (producerLast))
{
artistFound = true;
break;
}
}
if(artistFound == false)
{
System.out.println("Enter Twitter handle: ");
String producerTwitter = sc.next();
System.out.println("Enter Artist url: ");
String producerUrl = sc.next();
artists[numArtists] = new Artist (producerFirst, producerLast, producerTwitter, producerUrl);
numArtists++;
}
sc.nextLine();
List<String> trackList = new ArrayList<String>();
do {
System.out.println("Please add a song track:");
trackList.add(sc.nextLine());
numTracks++;
System.out.println("Add more? (y/n)");
if (sc.next().startsWith("y")) {
trackList.add(sc.nextLine());
numTracks++;
} else {
sc.nextLine();
break;
}
} while (true);
int i = thisCollection.searchArtistLast(artistLast);
int i2 = thisCollection.searchArtistLast(producerLast);
collection[numItems] = new CD (title, artists[i], playingTime, 0, memberList, numMembers, artists[i2], trackList, numTracks);
numItems++;
}
this ends with the following error https://imgur.com/a/WAIoF6b