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:
-
Class Recording that:
-
has three attributes / fields (select appropriate data types, access modifiers, and static/non-static yourself):
-
ARTIST (cannot be changed once set),
-
NAME (cannot be changed once set),
-
DURATION_IN_SECONDS (cannot be changed once set),
-
-
has two constructors:
-
non-parametrized constructor that will set both ARTIST and NAME attributes to Unknown and DURATION_IN_SECONDS to zero,
-
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,
-
-
has accessor / getter methods for all class attributes / fields,
-
has NO mutator / setter methods,
-
has a play method that will
-
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),
-
display ERROR: cannot play this recording message if duration is zero seconds,
-
-
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
Get step-by-step solutions from verified subject matter experts
