Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6840049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:47:36+00:00 2026-05-26T23:47:36+00:00

Following classes are created, no interface/abstract class for now: Test – for creating test

  • 0

Following classes are created, no interface/abstract class for now:

  1. Test – for creating test data
  2. Music – should store all CDs
  3. CD – should store Artist and CD title + all Songs
  4. Artist – only contains String name
  5. Song – contains default-constructor with (Artist anArtist, String songtitle, String Duration)
  6. Duration – for the song duration and later calculations

i tried an ArrayList, but it gets overwritten when i add another CD. I need a data type that stores the data with a link to another array. for example: store artist and title of CD1 and link to another array that contains all songs from CD1.

thanks

code from class Test:

Artist aArtist = new Artist("artist1");
        CD aCD = myMusic.addCD(aArtist, "CD1");
        aCD.addSong(aArtist, "song1", "1:00");

aArtist = new Artist("artist2");
        CD aCD = myMusic.addCD(aArtist, "CD2"); //Overwrites arraylist from CD1
        aCD.addSong(aArtist, "song2", "2:00");

i changed my ArrayLists in class Music and class CD… i think there is an easier way to solve that tutorial, but here is the code: (outputs all saved songs and CD title)

class Music:

    import java.util.ArrayList;

public class Music {
    private ArrayList<CD> myCDs = new ArrayList<CD>();

    public CD addCD(Artist anArtist, String cdTitle) {

        CD aCD = new CD(anArtist, cdTitle);
        myCDs.add(aCD);
        return aCD;
    }

    public void showData() {

        for (int i = 0; i < myCDs.size(); i++) {
            for (int j = 0; j < myCDs.get(i).getMyCD().size(); j++) {

                System.out.println(myCDs.get(i).getMyCD().get(j).getSong());
            }
        }

    }
}

class CD:

  import java.util.ArrayList;

public class CD {
    private String cdTitle;
    private ArrayList<Song> myCD = new ArrayList<Song>();

    public CD(Artist aArtist, String cdTitle) {
        setMyCD(aArtist, cdTitle);
    }

    public ArrayList<Song> getMyCD() {
        return myCD;
    }

    public String getMyCDtitle() {
        return cdTitle;
    }

    public void setMyCD(Artist anArtist, String cdTitle) {
        this.cdTitle = anArtist.getName() + ": " + cdTitle;
    }

    public void addSong(Artist anArtist, String aTitle, String aDuration) {

        myCD.add(new Song(anArtist, aTitle, aDuration));

    }
}

class Song:

 public class Song {
    private String song;

    public String getSong() {
        return song;
    }

    public void setSong(String song) {
        this.song = song;
    }

    public Song(Artist anArtist, String songtitle, String aDuration) {
        Duration songDuration = new Duration(aDuration);
        setSong(anArtist.getName() + ": " + songtitle + " ("
                + songDuration.getSongDuration() + ")");

    }

}

in general: how would you solve such a project ?
i would appreciate every advice or uml diagram.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:47:36+00:00Added an answer on May 26, 2026 at 11:47 pm

    This may be a problem with aArtist = new Artist("artist2");
    CD aCD = myMusic.addCD(aArtist, "CD2"); //Overwrites arraylist from CD1
    aCD.addSong(aArtist, "song2", "2:00");

    You use the same Artist object. If you post your addCD method implementation it will be more open for us.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following classes public interface InterfaceBase { } public class ImplementA:InterfaceBase {
I have several classes like in the following example: abstract class AClass { boolean
I have the following classes: Ingredients, Recipe and RecipeContent... class Ingredient(models.Model): name = models.CharField(max_length=30,
I have the following classes: public class Person { public String FirstName { set;
I have following classes. class A { public: void fun(); } class B: public
Consider the following classes in Java class A { protected void methodA() { System.out.println(methodA()
I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15)
Having the following classes, in two different assemblies: class Member { public string Label
I have the following classes defined to do validation: public class DefValidator : IValidate<IDef>
Consider the following code. public interface IFoo { } public class Bar { public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.