Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

MapLocation

Related Links:
Author: Robert Baxter (on 2013/01/22)

Suppose that a class MapLocation has been defined for storing information about a point of interest on a map. Each MapLocation object keeps track of a grid location (row and column) and a name.

The class includes the following members:

Type Name Description
field private char row row component of location
private int column column component of location
private String name name of the location
constructor public MapLocation(char row, int column, String name) constructs a MapLocation object with given row, column, and location
method public String getCoordinates() returns the map coordinates as a String (e.g. "C8")
public String getName() returns the name of this MapLocation
public String toString() returns a String representation of the MapLocation (e.g. "arboretum (C8)")

Your task is to modify the class to be Comparable by adding an appropriate compareTo method. MapLocation objects should be ordered first by increasing row and then by increasing column and then alphabetically by name.

Rows will be specified by character values in the range of A to Z inclusive and column locations will be specified as integers greater than 0, as in:

MapLocation loc = new MapLocation('C', 8, "arboretum");
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.