Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I hope some professors can help me. it is too hard... Thank you! Create a class

ID: 3772385 • Letter: I

Question

I hope some professors can help me. it is too hard... Thank you!

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. Put your name in both files.

Explanation / Answer

class CD{


   private String artist;
   private String album;
   private int numberoftracks;
   private static int cdCount=0;

   public void cd(String artist,String album,int numberoftracks){
       this.artist=artist;
       this.album=album;
       this.numberoftracks=numberoftracks;
   }

  
   public String getArtist() {
       return artist;
   }

   public void setArtist(String artist) {
       this.artist = artist;
   }

   public String getAlbum() {
       return album;
   }

   public void setAlbum(String album) {
       this.album = album;
   }

   public int getNumberoftracks() {
       return numberoftracks;
   }

   public void setNumberoftracks(int numberoftracks) {
       this.numberoftracks = numberoftracks;
   }

   public static int getCdCount() {
       return cdCount;
   }

   public static void setCdCount(int cdCount) {
       CD.cdCount = cdCount;
   }
  
   public String toString(){
       return artist+" "+album+" "+numberoftracks;
   }

}


public class CDTest {
   public static void main(String hh[]){
       CD cd=new CD();

       String cds[]=new String[20];
       cd.getCdCount();
   }

}