Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write the following program in Java, use comments texplaining 1. Class Recording that: a) has three attributes / fields (select appropriate data types, access modifiers,
Write the following program in Java, use comments texplaining
1. Class Recording that: a) has three attributes / fields (select appropriate data types, access modifiers, and staticon-static yourself): I. ARTIST (cannot be changed once set), ii. NAME (cannot be changed once set), iii. DURATION_IN_SECONDS (cannot be changed once set), b) has two constructors: I non-parametrized constructor that will set both ARTIST and NAME attributes to "Unknown" and DURATION IN SECONDS to zero, ii. 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, c) has accessor/getter methods for all class attributes/fields, d) has NO mutator /setters methods, e) has a play method that will I. 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 3m215), ii. display "ERROR: cannot play this recording" message if duration is zero seconds, f) 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). 2. Class Playlist that: a) has the following attributes / fields (select appropriate data types, access modifiers, and staticon-static yourself): i. name, il numberOf Recordings, that will hold the CURRENT number of recordings (Initialize to zero), ill. duration InSeconds, that will hold the TOTAL duration of all recordings in the playlist (initialize to zero), iv. MAX_PLAYLIST_SIZE, that sets the limit of recordings that this playlist can hold (cannot be changed once set), v. an array of recordings called recordingList, b) has two constructors: i. non-parametrized constructor that will: 1. set the name attribute / field value to "Unknown", 2. set the MAX_PLAYLIST_SIZE attribute / field to 5, 3. initialize the array, ii. parametrized constructor that constructor that will set not initialized 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, c) has accessor/getter methods for all class attributes/fields, d) has ONE mutator / getter method for the name attribute / field that makes sure that null names are not allowed, has an add method that allows you to add a new recording to your playlist that: i. prevents from adding "null recordings", ii. prevents from exceeding playlist size, ill. updates all corresponding attributes / fields accordingly, iv. returns true if adding was successful (recording added), and false otherwise (recording could not be added), f) has a method play that will use Recording object method to "play" all recordings in the playlist in sequence (see example below). If the playlist is empty, it should display "ERROR: empty playlist" message, B) has a method toString that will display a playlist summary as shown in example below. If your Recording and Playlist classes are implemented correctly, the following application class: Playlist Demo.java class public class Playlist Demo public static void main(String[] args) { // Instantiate new playlist Playlist myPlaylist = new Playlist ("CS 116 Playlist", 10); // Add some songs to it Recording newRecording = new Recording ("Billie Eilish", "Everything I Wanted", 201); myPlaylist.add(newRecording); newRecording = new Recording ("Eminem", "Godzilla", 245); myPlaylist.add(new Recording); new Recording = new Recording ("The Weeknd", "Blinding Lights", 145); myplaylist.add(newRecording); newRecording = new Recording ("Nicki Minaj", "Yikes", 217); myplaylist.add(newRecording); newRecording = new Recording ("Justin Bieber", "Intentions", 234); myplaylist.add(newRecording); // "Play" the playlist myPlaylist:Play(); // Display playlist "summary" System.out.println (myPlaylist.toString()); Should generate this output (note how play and toString methods work): Now playing: Billie Eilish - Everything I Wanted (3m21s] Now playing: Eminem - Godzilla [4m5s ] Now playing: The Weeknd - Blinding Lights [2m25s ] Now playing: Nicki Minaj - Yikes [3m3 7s] Now playing: Justin Bieber - Intentions [3m54s] Playlist: CS 116 Playlist [17m22s] : Billie Eilish - Everything I Wanted [3m21s] Eminem - Godzilla [ 4m5s ] The Weeknd - Blinding Lights (2m25s] Nicki Minaj - Yikes [3m37s] Justin Bieber - Intentions [3m54s]Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started