Question: I need code to have the following: Class Recording that: has three attributes / fields (select appropriate data types, access modifiers, and static/non-static yourself): ARTIST

I need code to have the following:

  1. Class Recording that:

    1. has three attributes / fields (select appropriate data types, access modifiers, and static/non-static yourself):

      1. ARTIST (cannot be changed once set),

      2. NAME (cannot be changed once set),

      3. DURATION_IN_SECONDS (cannot be changed once set),

    2. has two constructors:

      1. non-parametrized constructor that will set both ARTIST and NAME attributes to Unknown and DURATION_IN_SECONDS to zero,

      2. parametrized constructor that will set all class attributes to desired values IF these area not null and valid/legal. Otherwise set them the same way as in the non-parametrized constructor,

    3. has accessor / getter methods for all class attributes / fields,

    4. has NO mutator / setter methods,

    5. has a play method that will

      1. display a message Now playing: artist - name [XXmYYs], where artist is the value of the artist attribute / field, name is the value of the name attribute / field, XX is the number of full duration minutes, and YY is the number of remaining seconds (no need to use leading zeros; for example duration of 201 seconds would be represented by 3m21s),

      2. display ERROR: cannot play this recording message if duration is zero seconds,

    6. Has a toString method that will display a message artist - name [XXmYYs], where artist is the value of the artist attribute / field, name is the value of the name attribute / field, XX is the number of full duration minutes, and YY is the number of remaining seconds (no need to use leading zeros; for example duration of 201 seconds would be represented by 3m21s).

This is what I have so far and I know that I did somethings not correctly, so would you be able to fix them?

class Recording{

String ARTIST; String NAME; int DURATION_IN_SECONDS; Recording(){ ARTIST = "Unknown"; NAME = "Unknown"; DURATION_IN_SECONDS = 0; } Recording(String ARTIST, String NAME, int DURATION_IN_SECONDS){ this.ARTIST= ARTIST; this.NAME = NAME; this.DURATION_IN_SECONDS = DURATION_IN_SECONDS; } public String getArtist(){ return ARTIST; } public String getName(){ return NAME; } public int getDuration(){ return DURATION_IN_SECONDS; } public void Play(){ if (DURATION_IN_SECONDS > 0){ int s = DURATION_IN_SECONDS % 60; int h = DURATION_IN_SECONDS / 60; int m = h % 60; System.out.println("Now Playing:"+ARTIST+"-" +NAME+ "[" +m+"m" +s+"s]"); } else { System.out.println("ERROR: cannot play this recording"); } } public String toString(){ int s = DURATION_IN_SECONDS % 60; int h = DURATION_IN_SECONDS / 60; int m = h % 60; return ARTIST +"-"+NAME +"[" +m+"m" +s+"s]"; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!