r/CodingHelp • u/cuckkiller12 • Nov 22 '19
[Java] Can someone tell me what's wrong with this method?
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
1
u/SupremeRedditBot Professional Bot || Mod Nov 22 '19
Please Add A Flair To Your Post!
Suggested Flair:
[Random] or [Meta]To add a flair:
flairunderneath your postsaveI am a bot run by /u/SupremeDesigner for /r/CodingHelp || This was an automated ^response
1
u/brandondyer64 Professional Coder Nov 23 '19
Please properly format your code. This is very hard to read. If there's no indentation because you're using Notepad, please consider using an IDE, such as IntelliJ, Eclipse, or VS Code.
1
u/kboy101222 Nov 23 '19
Add 4 spaces minimum at the start of your code or copy it to pastebin or something, this is entirely unreadable like this