Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a class RadioStation that has the following Three instance variables Name

ID: 3763777 • Letter: C

Question

Create a class RadioStation that has the following Three instance variables Name - The name of the radio station. Frequency - A decimal value from 87.5 to 108.0 that represents the frequency modulation band of the station in megahertz. Playlist - An array of 50 strings which correspond to what is currently and to be played. The current song or show that is always at the first index. Two constructors i. Default - set the instance variables to a correct default value One that takes in three parameters that will set the instance variables while also checking values. Accessors and Mutators for all instance variables. Make sure to check f invalid values for frequency's mutator. The others do not have to check for invalid values. A method addToPlaylist which returns nothing and takes in a siring value to add to the end of the playlist. If the playlist is full make sure to prom] the user. A method next which returns nothing and takes in no values, but it replaces the first element of the playlist with the next element, and so on until it reaches the end of the list. (Think of it shifting everything to the f. A method currentlyPlaying which returns the first element of the playling. A static method createStation which takes in a name, frequency, and a playlist and returns a new instance of a radio station.

Explanation / Answer


public class RadioStation {

   String name;
   double frequency;
   String[] playlist = new String[50];
  
   public RadioStation() {
       super();
       this.name = "";
       this.frequency = 87.5;
   }

   public RadioStation(String name, double frequency, String[] playlist) {
       super();
       this.name = name;
       if(frequency >= 87.5 && frequency <= 108.0)
       {
           this.frequency = frequency;
       }
       this.playlist = playlist;
   }

   public String getName() {
       return name;
   }

   public void setName(String name) {
       this.name = name;
   }

   public double getFrequency() {
       return frequency;
   }

   public void setFrequency(double frequency) {
       if(frequency >= 87.5 && frequency <= 108.0)
       {
           this.frequency = frequency;
       }
   }

   public String[] getPlaylist() {
       return playlist;
   }

   public void setPlaylist(String[] playlist) {
       this.playlist = playlist;
   }
  
   public void addToPlaylist(String song) {
       int len = this.playlist.length;
       if(len < 50) {
           this.playlist[len++] = song;
       }
       else {
           System.out.println("Cannot add to the playlist");
       }
   }
  
   public void next() {
       for(int i = 1; i < this.playlist.length; i++) {
           this.playlist[i-1] = this.playlist[i];
       }
   }
  
   public String currentlyPlaying() {
       return this.playlist[0];
   }
  
   public static RadioStation createStation(String name, double frequency, String[] playlist) {
       return new RadioStation(name, frequency, playlist);
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote