3.1b Radio Project

Framing the Project (real-world):

You will be creating an object that represents an FM car radio.  You will be simulating the various controls of the radio such as volume control, tuning to various stations, preset stations, and turning it on and off.  Specifically the radio will have:

  • 5 preset stations

  • a volume control

    • minimum level of 0

    • maximum level of 20

  • a mute button

    • if the mute is on the all other controls (methods) will not change the volume

    • when the mute is turned off, the loudest volume it will go back to is 10

  • a tuner control

    • minimum frequency of 87.5

    • maximum frequency of 108.0

  • on / off switch

When the radio has been used and is turned off, the next time the radio is turned on:

  • if the mute is on, it will be turn off

  • the previously set volume level will be used but the volume will not be over 10

  • the current station will be the same station as when the radio was turned off

Program Design

Class Name:  FMRadio()



final double MAX_FREQUENCY = 108.0

final double MIN_FREQUENCY = 87.5

final int MAX_VOLUME = 20

final int MIN_VOLUME = 0

Instance variables (visibility for all instance variables is private):

isOn, type: boolean

  • the status of the radio - true/false for on/off

  • initialize to false (off)

isMuted, type:  boolean

  • the status of the mute feature - true/false for on/off

  • initialize to false (off)

mutedVolume, type: int

  • the volume to set when the mute is turn off

  • initialize to MIN_VOLUME

currentStation, type: double

  • station radio is currently tuned to

  • all stations must be between MAX_FREQUENCY and MIN_FREQUENCY (inclusive)

  • initialize to MIN_FREQUENCY

volume, type: int

  • current volume level

  • volume must be between MAX_VOLUME and MIN_VOLUME (inclusive)

  • initialize to MIN_VOLUME

presetStation[ ], type: double array

  • array with 5 locations

  • each location stores a radio station frequency

  • initialized by resetRadio() in constructor


  • initialize instance variables as indicated above

  • invoke resetRadio()




  • the volume is set to 0

  • all preset stations and the current station are set to MIN_FREQUENCY

  • the radio is off

  • the mute is off


  • set all preset station to MIN_FREQUENCY



  • display on the system console, the current settings for the radio

    • on/off

    • station

    • mute on/off

    • volume

    • station settings for each of the 5 presets


  • increase the volume by 1


  • decrease the volume by 1

setPresetStation(int presetNumber)

  • save the currentStation to the  presetNumber

  • display a message similar to “Preset 1 set to 98.1”


  • increase the currentStation frequency by 0.1


  • decrease the currentStation frequency by 0.1

changeStation(int preset)

  • change the current station to the preset station

changeStation(double station)

  • change the currentStation to the station


  • increase the frequency of the station by 0.5

  • if the station is too high, set the station to the minimum frequency


  • decrease the frequency of the station by 0.5

  • if the station is too low, set the station to the maximum frequency


  • if the radio isMuted

    • set the volume to the mutedVolume

    • set isMuted to false

  • otherwise

    • sets the volume to 0

    • set isMuted to true


  • turn on the radio if it is off and off if it is on