Create a class CD with private instance variables artist, album, and number of t
ID: 3772337 • Letter: C
Question
Create a class CD with private instance variables artist, album, and number of tracks and a private static variable cdCount. The class has one constructor that takes three arguments. The constructor must count each CD. Be sure to code get/set methods for each instance variable, and a toString method. The toString method returns the information about the CD as a String, clearly labeled. Be sure to validate the number of tracks (no negative or zero value allowed – use default value
1). There should also be a static method getCdCount.
Create an application CDTest with an array named cds that will hold 20 CD objects. Create 4 CDs and store them in the array. Then walk through the array using a loop and output the CD data. You must use the cdCount value for this (call the get method). Use the command prompt (console) for output. Do everything in main. Use an editor to create the CD class and the test program, then zip both .java files and drag and drop the zip file below. Be sure to save your test frequently so that you will not be logged off for inactivity.
Example:
Artist: Weird Al Yankovic Album: Mandatory Fun Tracks: 12
Explanation / Answer
Program:
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.