Need Java help creating a class CD?

Im just asking for help to get started on how to make a CLASS representing a cd containing strings for titles, and artists aswell as an array of strings to hold up tracktitles. this class must implement methods for:

-its constructor which will initialize title and artist

-AddTrackString tracktitle to add tracktitle

-Display(), which uses println to display the artist, title, and each numbered track on a seperate line.

basically if someone could help me by offering a simple outline of where methods, fields, data, constructors go it would really help me alot by learning Java. Thanks!

Answer
? Favorite Answer

  • I’ll show you the order of where elements usually go. Below that I’ll put some **** and there it will be the program you are asking about, so you can try it on your own and see if you did it right. I’ll also comment my code so you can understand it. (P.S. I’ll assume this is a beginners java class so I used arrays, but it almost sounds like it would be better using arraylists, since it may not have tracks, right now I just didn’t print out the ones the are null). Message me if you still don’t get it or want to use arraylists instead.

    //Defines class

    public class name {

    //Variables are defined here

    variables

    //Constructor. You can initialize variables here

    constructor(){

    }

    //Put both of your methods after constructor

    methods(){

    }

    //Main to run your program

    public static void main(String[] args) {

    }

    }

    *************MY PROGRAM**************

    See also  Types of NET Framework classes supported in VB.NET?

    public class CD {

    //Create variables

    public String artist;

    public String title;

    public String[] trackListing = new String[];

    int current = ;//Need this to put songs in correct spot in array

    //Constructor. Initializes the artist and title variables based on parameters ()

    public CD(String artist, String title){

    this.artist = artist;

    this.title = title;

    }

    //Method that adds a track to the array based on whats in parameters

    public void addTrackListing(String trackTitle){

    trackListing[current] = trackTitle;

    current++;

    }

    //Prints the artist and title, then loops through array and prints out song titles

    public void display(){

    System.out.println(“Artist: ” + artist);

    System.out.println(“Title: ” + title);

    for(int i = ; i < trackListing.length; i++){

    if(trackListing[i] != null){

    System.out.println(“Track ” + (i+) + “: ” + trackListing[i]);

    }

    }

    }

    public static void main(String[] args) {

    //Create cd object

    CD cd = new CD(“Coldplay”,”Viva La Vida”);

    //Add tracks

    cd.addTrackListing(“Life In Technicolor”);

    cd.addTrackListing(“Cemeteries of London”);

    //Display info

    cd.display();

    }

    }

  • Other Related Questions

    Learning Visual Basic ?

    Answers Favorite AnswerTry using "System.Diagnostics.Process. GetProcessesByName( "iwmp" ).Length > " for your check.

    Microsoft Office word Fast answer needed its urgent?

    Answers Favorite AnswerTry this:http://www.techsupport.com///microsoft-wo...Here is another thread re: the same issue with instructions:http://www.pcreview.co.uk/forums/modification-not-...http://www.techsupport.com///microsoft-wo...http://support.microsoft.com/kb/http://answers.microsoft.com/en-us/office/forum/of...

    Can I download a whole city android google maps?

    Answers Favorite Answer:) Yes!!!Interesting question. I wonder why it has blocked in this way especially considering that Google Earth is very detailed and has good maps of Israel.

    What is meant by ROM ? Explain in simple but elaborate terms.What about mobile ROM’s?

    Answers Favorite AnswerHi Diva below is a link that will give a simple answer.http://wiki.answers.com/Q/What_does_ROM_stand_for_...Hope this helps.Source(s): Experience and wiki answers.ROM is Read only memory. i.e data can write only once.There two types of ROM..ROM.PROMThe difference between ROM and PROM.that is ROM is programmed during manufacturing it means data stored by manufacturing company.PROM is blank memory that a user programmable memory.user can store content on PROM.both ROM and PROM are Read only memory Data can write only once.and its not possible to write so many time.Memories of PROM and ROM are Non-volatile in nature. Its that stored informations can retain even power goes off.

    See also  The Java programming language is a high-level language that can be characterized by all of the following buzzw?

    Leave a Comment