Question
java

With the incredible royalties on your Jukebox-management code, to become a DJ. You realize that you can adapt the Jukebox cod
gswithBPM (int bpm) that returns a collection of Songs that (c) Write a DJ instance method getSon have the given bpm value. A
(e) Using the code you wrote in part (d), write a DJ instance method getHighestRatedSong ( that returns the highest-rated son
With the incredible royalties on your Jukebox-management code, to become a DJ. You realize that you can adapt the Jukebox code to create some sophistica software for your new career. Consider the slightly simplified versio As a DJ, you are mainly interested in the BPM (beats per minute) and rating of the songs. you decide to indulge your dream n of the book's Song class below. public class Song private String title private String artist; private int rating private int bpm; public String getArtist) return artist; ) public int getBpm) return bpm; ) public int getRating) return rating ) public String getTite) return title ) You have already adapted a lot of the Jukebox code; in particular, you have already written most of a DJ class, which has an instance variable ArrayList songlist. Now you need to write a method, makeBpmMap (), that will make it easy for you to find all the songs that have a given BPM value.
gswithBPM (int bpm) that returns a collection of Songs that (c) Write a DJ instance method getSon have the given bpm value. Assume bpmMap has been filled with useful data by the makeBpmMap) method. (d) As a DJ, you also need to be able to sort a list of Songs so that you can quickly see which ones are highest rated. Without modifying the Song class, write code that will make this possible.
(e) Using the code you wrote in part (d), write a DJ instance method getHighestRatedSong ( that returns the highest-rated song in songlist. (Or one of them, if there are multiple Songs with the same rating.)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

JAVA PROGRAM

package test.song;

import java.util.ArrayList;
import java.util.HashMap;

public class TestSong {
  
   public static void main(String[] args){
      
       //song instaces created
       Song s1 = new Song("English Rock","XXX",4,100);
       Song s2= new Song("Spanish Rock","XXX",4,120);
       Song s3 = new Song("Hindi clssical Rock","",4,180);
       Song s4= new Song("Spanish Rock","XXX",4,95);
      
       DJ dj = new DJ();
       //instances are added into dj object
       dj.getSongList().add(s1);
       dj.getSongList().add(s2);
       dj.getSongList().add(s3);
       dj.getSongList().add(s4);
      
      
       HashMap<Integer, ArrayList<Song>> bpmMap = dj.getBpmMap(); //bmpMap is created
      
       System.out.println("The highest rated song is:"+ dj.getHighestRatedSong());
      
      

   }

}

--------------------------------------------------------------

package test.song;

public class Song {
   private String title;
   private String artist;
   private int rating;
   private int bpm;
  
   //constructor for Song
   public Song(String title, String artist, int rating, int bpm) {
       this.title = title;
       this.artist = artist;
       this.rating = rating;
       this.bpm = bpm;
   }
   public String getTitle() {
       return title;
   }
   public String getArtist() {
       return artist;
   }
   public int getRating() {
       return rating;
   }
   public int getBpm() {
       return bpm;
   }
  
   //overridden to string method
   @Override
   public String toString() {
       return "Song [title=" + title + ", artist=" + artist + ", rating=" + rating + ", bpm=" + bpm + "]";
   }
  
  
  

}

--------------------------------------------------------------------------------

package test.song;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;

public class DJ {
  
   private ArrayList<Song> songList = null;
  
   private HashMap<Integer,ArrayList<Song>> bpmMap = null;
  
   //trough DJ constructor songlist is initialized
   public DJ(){
       songList = new ArrayList<Song>();
   }
  
  
  
   public ArrayList<Song> getSongList() {
       return songList;
   }


   public void setSongList(ArrayList<Song> songList) {
       this.songList = songList;
   }


   public HashMap<Integer, ArrayList<Song>> getBpmMap() {
       return bpmMap;
   }


   public void setBpmMap(HashMap<Integer, ArrayList<Song>> bpmMap) {
       this.bpmMap = bpmMap;
   }

   /**
   * this mehod will return list of songs by bmpRate
   * @param bpmRate
   * @return
   */
   public ArrayList<Song> getSongsWithBpm(int bpmRate){
           return this.bpmMap.get(bpmRate);
   }
  
   /**
   * sort the songs based on highest ratings
   * h
   */
   private void sortSongsByRating(){
       Collections.sort(songList, new Comparator<Song>(){

           @Override
           public int compare(Song s1, Song s2) {
               if(s1.getRating() > s2.getRating()){
                   return 1;
               }else if(s1.getRating() < s2.getRating()){
                   return -1;
               }else{
                   return 0 ;
               }
           }
          
       });
   }
  
   /**
   * THIS WILL CALL sortSongsByRating
   * and take the first Song object
   * @return
   */
   public Song getHighestRatedSong(){
       sortSongsByRating();
      
       return this.songList.get(0);
   }
  
  

}

====================================

OUTPUT

The highest rated song is:Song [title=English Rock, artist=XXX, rating=4, bpm=100]

Add a comment
Know the answer?
Add Answer to:
java With the incredible royalties on your Jukebox-management code, to become a DJ. You realize that you can adap...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player --...

    Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the...

    JAVA PROGRAMMING Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones...

  • Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...

    Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Classics.txt (see Code Listing 7.3) from the Student Files or as directed by your instructor. Song.java is complete and will not be edited. Classics.txt is the data file that will be used by Compact Disc.java, the file you will be editing. 2. In Compact Disc.java, there are comments indicating where the missing code is to be placed. Declare...

  • public class Song { private String title; private String artist; private int duration; public Song() {...

    public class Song { private String title; private String artist; private int duration; public Song() { this("", "", 0, 0); } public Song(String t, String a, int m, int s) { title = t; artist = a; duration = m * 60 + s; } public String getTitle() { return title; } public String getArtist() { return artist; } public int getDuration() { return duration; } public int getMinutes() { return duration / 60; } public int getSeconds() { return...

  • THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode...

    THE ENTIRE CODE SHOULD BE IN JAVA Playlist (output linked list) Given main(), complete the SongNode class to include the printSongInfo() method. Then write the Playlist class' printPlaylist() method to print all songs in the playlist. DO NOT print the dummy head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You Don't Own Me 151 Lesley Gore -1 the output is: LIST OF SONGS ------------- Title: Stomp! Length: 380 Artist: The Brothers...

  • is there anyway you can modify the code so that when i run it i can...

    is there anyway you can modify the code so that when i run it i can see all the song when i click the select button all the songs in the songList.txt file can be shown song.java package proj2; public class Song { private String name; private String itemCode; private String description; private String artist; private String album; private String price; Song(String name, String itemCode, String description, String artist, String album, String price) { this.name = name; this.itemCode = itemCode;...

  • For Java please.Artwork. javaimport java.util.Scanner;public class ArtworkLabel {public static void main(String[] args)...

     Given main(). define the Artist class (in file Artist java) with constructors to initialize an artist's information, get methods, and a printlnfo() method. The default constructor should initialize the artist's name to "None' and the years of birth and death to 0. printinfo() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class (in file Artwork.java) with constructors to initialize an artwork's information, get methods, and a printinfo() method. The constructor should...

  • public enum Rating {               GENERAL(0),        PARENTALGUIDANCE(1),        MATURE(2);     

    public enum Rating {               GENERAL(0),        PARENTALGUIDANCE(1),        MATURE(2);               private int minAge;               private Rating(int i)        {              minAge = i;        }               public int getMinAge()        {              return minAge;        }               public void setMinAge(int age)        {              minAge = age;        }               public String toString()        {              switch(this)              {              case GENERAL:                     return "G";              case PARENTALGUIDANCE:                     return "P";              case MATURE:                     return...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT