logo Practice-It logo


Related Links:
Author: Marty Stepp

Suppose that a class RadioStation has been defined for storing information about radio stations. Each station object keeps track of its name (a string), its broadcast band (a string) and its station number (a real number). For example, there is a local station called KUOW that is an FM station broadcast on 94.9. The class includes the following members:

private String name name such as "KUOW"
private String band band such as "FM" or "AM"
private double station station such as 94.9
private RadioStation link link to simulcast partner station (null if none)
public RadioStation(String name, String band, double number) constructs a station with given name, band, station #
public String getName() returns the name
public String getBand() returns the band
public double getStation() returns the station number
public String toString() returns a String representation of the radio station
public void simulcast(RadioStation other) records that this station and the other are simulcasts

Your task is to modify the class to be Comparable by adding an appropriate compareTo method. Radio stations should be grouped together by band (e.g., all AM stations grouped together and all FM stations grouped together). Within a given band, the stations should be sorted by station number (e.g., FM 94.9 less than FM 96.5).

The broadcast band can be any arbitrary string. For example, it might be "AM" versus "FM" or might include subdivisions like "FM 1" and "FM 2" or might include other text like "XM" for satellite radio.

Type your solution here:

This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.