Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I take an error with my codes how can I fix this kind of error points) You are going to develop a class to represent

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

I take an error with my codes how can I fix this kind of error

image text in transcribed

image text in transcribed

points) You are going to develop a class to represent Songs. *For the instance variables, add the below ones. Make sure that these values cannot be accessed from other classes. Name of the artist Name of the song Duration of the song(in seconds) Play count *Write at least two constructors (not the default one) (Hint: When you first create a song, play count should be 0) *For this class, make sure you follow the encapsulation rules. (Add methods that you think are necessary for encapsulatic *Add an additional play method that increases the play count. *Override the toString method. Return everything in a proper format. *Implement a class that will represent a Music Album that contains songs. *For the instance variables, add the below ones. Make sure that these values cannot be accessed from other classes. name of the album number of songs songs[] *Write at least two constructors (not the default one) *For this class, make sure you follow the encapsulation rules. (Add methods that you think are necessary for encapsulation) *Write one additional method to add songs to this album. *Write one additional method to search a song by the artist's name in this album. If you can find it, return it. *Write one additional method to search a song by the song name in this album. If you can find it, return it. *Write another method to decide the top song in this album which is the most played song and display it. *Override the toString method. Return everything including the song names. *Finally, use this class with a main method. Create a couple of songs. Then create an album with these songs. Play them randomly. Search the songs, call the necessary methods and at the end show us which song is the top song. The general flow is up to you but make sure you call search methods, play method, add method and tostring methods. WHEN YOU COPY PASTE TO THE BELOW AREA, THE FOR SHOULD BE LIKE THIS OPY THE SONG CLASS (ADD THIS DASHES TO SEPERATE THE CLASSES COPY THE ALBUM CLASS (ADD THI EPERATE THE CLASSES COPY YOUR MAN METHOD Album.java testii.java 60 1 2 public class song Song> { 3 private String artistName; 4 private String songName; 5 private int duration; 6 private int playCount; 7 8 90 public song (String artistName String songName , int duration) { 10 this.artistName = artistName; 11 this, songName = songName; 12 this, duration : duration; 13 } 140 public song( String artistName, String songName, int duration, int playCount ) { 15 this.artistName = artistName; 16 this, songName = songName; 17 this, duration = duration; 18 this.playCount = playCount; 19 } 200 public String getArtistName() { 21 return artistName; 22 } 230 public void setArtistName(String artistName) { 24 this.artistName = artistName; 25 } 26 public String getSongName() !! 27 return songName; 28 } 29 public void setSongName(String songName) { this, songName = songName; 31 } 32 public int getDuration() { 33 return duration; 34 } 350 public void setDuration(int duration) { 36 this, duration = duration; 37 } 380 public int getPlayCount() { 30 public String getArtistName() { return artistName; Be public void setArtistName(String artistName) { this.artistName = artistName; 50 public String getSongName() return songName; 3 30 public void setSongName(String songName) { this.songName = songName; 2 public int getDuration() { 3 return duration; 50 public void setDuration(int duration) { 6 this. duration = duration; 7} 80 public int getPlayCount() { return playCount; -10 public void setPlayCount(int playCount) { -2 this.playCount = playCount; 13 } 14 15 @Override 16 public String toString() { 17 return "Song(artistName=" + artistName + SongName=" + songName + ",Duration=" + duration + ", PlayCount=" + playCount + "1" ; 18 79} 500 public void play(@SuppressWarnings("rawtypes") song s) { 51 s.playCount++; 52 } 53 54 9 55 O.JOVE program.jave song.java Album.jave testii java 60 import java.util.ArrayList; import java.util.List; public class Album private String albumName; private int numberOfSongs: @SuppressWarnings("rawtypes") private ArrayListsongs = new ArrayList(); public Album(String albumvame ) { this album lame = albumName; B Bo public String getAlbumName() { return albumName; to public void setAlbumName(String albumllame) { this.albumName = albumName; 70 public int getNumberOfSongs(int i) { return numberOfSongs; 30 public void setNumberOfSongs(int numberOfSongs) { this numberOfSongs = numberOfSongs; 26 @SuppressWarnings("rawtypes") 1 public ArrayList getSongs() { return songs; 40 public void setSongs(@SuppressWarnings("rawtypes") ArrayList songs) { 5 this, songs = songs; 6} 70 @Override 8 public String toString() { 9 return "Album (albumName=" + albumName + ", NumberofSongs=" numberOfSongs", Songs="songs "]": 2 1easures sharias unchecked autan eSuppressWarnings({ "unchecked", "rawtypes" )) public void addsong song songs) ((List) songs).add( songs): @SuppressWarnings("rawtypes") public song searchSongBySongName(String songName) { for (song s songs) if(s.getSongName() = songame) return S: return null; 10 asuppressWarnings("rawtypes") public song SearchSongByArtistName(String artistName) { for (songs : songs) { if(s.getArtistName() = artistName) { return s; 0 } 1 return null; 2} 30@SuppressWarnings("rawtypes") 4 public song topSong() { 55 int max =0; 56 song top = null; 57 for(song 5 songs 58 if(s.getPlayCont() > max) 59 max = s.getPlayCount(); 70 top = s; 71 } 72 73 return top: 74 } 75 76 77 78); . 33); . 5); 4); public class testii { Bo @SuppressWarnings("rawtypes") public static void main(String[] args) { song s1 = new song ("a' "b" song s2 = new song ("e" song s3 = new song ("p" song s4 = new song ("C" Album al = new Album("XYZ"); al.addSong (S1): al.addSong (s2); al.addSong (53); al.addSong (54); -4 al.getNumberOfSongs(4); -5 $1.play(51); 26 System.out.println(s1.toString()); 17 s2.play(s2); 18 53.play(3) 19 54.play(s); 20 s1.play(51); 21 $1.play(51); 22 s2.play(52); 23 24 System.out.println(ai. searchSongBySong lame("b")); 25 System.out.println(al. SearchSongByArtistName("p")); 26 System.out.println("Top song is: + al.topSong()); 27 28 29 Problems @ Javadoc Console IXXBT testii (Java Application) /Users/ayanajim/.p2/pool/plugins/org.eclipse.justj.openjdk.hotspot.jre.full.macosx.x86_64_14.0.2.v20200815-0932/jre/bin/java (Feb 15, 2021, 9:30:52 PM-9:30:53 PM) Exception in thread "main" java.lang.ClassCastException: class song cannot be cast to class java.util.List (song is in unnamed module of at Album.addSong (Album.java:43 at testii.main(testii.java:10 Problems Javadoc Console XX

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions

Question

distinguish between full-cost and direct-cost pricing

Answered: 1 week ago

Question

What physical locations do you work in?

Answered: 1 week ago