teaching machines

Homework 6 – A-routes – due December 15

August 29, 2019 by . Filed under cs1, fall 2019, specifications.

Your objective in this homework is to learn how to marry data and code—or state and behaviors—into objects. You will do this in the context of writing a program that maps routes of runs (or jogs or walks) in Google Earth or Google Maps. The intent of the program is to promote exercise by making available a catalog of routes that are interesting in that they trace out meaningful or humorous shapes or words. In this homework, we name such routes A-routes, or Arts for short.

This assignment is more involved and less easy to test in small chunks than your previous assignments. Plan accordingly.

Before we dig into the specification, let’s talk about the structure of an A-route and its file format.

A-route

Consider the following file that describes an A-route:

artist Chris Johnson
name Helleau, Claire!
description
This is how I greet each day.
enddescription
leg
name h
closed false
waypoint 44.801799 -91.491848
waypoint 44.799473 -91.492579
waypoint 44.800465 -91.492256
waypoint 44.799940 -91.489048
waypoint 44.798897 -91.489402
endleg
leg
name base of i
closed false
waypoint 44.798638 -91.487889
waypoint 44.799698 -91.487546
waypoint 44.801051 -91.487363
endleg
leg
name jot of i
closed true
waypoint 44.801744 -91.487277
waypoint 44.802452 -91.487889
waypoint 44.802916 -91.486591
waypoint 44.802178 -91.486323
endleg

Let’s walk through this file in chunks. Here’s the first section:

artist Chris Johnson
name Helleau, Claire!
description
This is how I greet each day.
enddescription

This section defines who designed the A-route and gives it a meaningful name and description. Following are descriptions of the route’s three legs, like this one:

leg
name h
closed false
waypoint 44.801799 -91.491848
waypoint 44.799473 -91.492579
waypoint 44.800465 -91.492256
waypoint 44.799940 -91.489048
waypoint 44.798897 -91.489402
endleg

As suggested by the name, this leg draws a lowercase H. It is not closed; it does not end where it started. It consists of five latitude-longitude pairs, or waypoints, that define the path.

Normal runs consist of a single leg. To support more kinds of drawing, however, we allow A-routes to consist of a series of disconnected legs. In a sense, each leg is a separate stroke, in between which the runner “lifts the pen.” Here, the second and third legs draw the two parts of a lowercase I.

KML

In this homework, we’ll collect a bunch of these A-routes into a catalog of the routes organized by artist. This catalog is expressed in the Keyhole Markup Language (KML). The name derives from Keyhole, Inc., a geoinformatics company acquired by Google in 2004 as part of its expansion into mapping services.

If our catalog contains only the example above, our program produces the following KML file:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>A-routes by Artist</name>
<Style id="polylineStyle">
<LineStyle>
<color>b3004dff</color>
<width>10</width>
</LineStyle>
</Style>
<Folder>
<name>Chris Johnson</name>
<Folder>
<name>Helleau, Claire!</name>
<description>This is how I greet each day.</description>
<Placemark>
<name>h</name>
<styleUrl>#polylineStyle</styleUrl>
<LineString>
<coordinates>
-91.491848,44.801799
-91.492579,44.799473
-91.492256,44.800465
-91.489048,44.799940
-91.489402,44.798897
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>base of i</name>
<styleUrl>#polylineStyle</styleUrl>
<LineString>
<coordinates>
-91.487889,44.798638
-91.487546,44.799698
-91.487363,44.801051
</coordinates>
</LineString>
</Placemark>
<Placemark>
<name>jot of i</name>
<styleUrl>#polylineStyle</styleUrl>
<LineString>
<coordinates>
-91.487277,44.801744
-91.487889,44.802452
-91.486591,44.802916
-91.486323,44.802178
-91.487277,44.801744
</coordinates>
</LineString>
</Placemark>
</Folder>
</Folder>
</Document>
</kml>

When we view this file in Google Earth, we see this map:

You can test this yourself by saving the file to your computer and opening it in Google Earth.

In general, we can expect many files to be in the catalog, with many artists having designed many runs. These can be navigated using the hierarchy in the left pane.

Google Maps

KML files can also be viewed in Google Maps. To load a KML file into Google Maps, follow these steps:

However, Google Maps doesn’t support all features of KML. In particular, it doesn’t acknowledge the hierarchical organization of the artist catalog. For this reason, we recommend downloading and testing with Google Earth.

Creating Your Own

To create your own map, handcraft an A-route file. To determine the waypoints, visit Google Maps, find some roads or trails that will support the shapes or words that you want to trace, and identify the latitude-longitude pairs by tapping on the map or right-clicking and selecting What’s Here? A small dialog will appear at the bottom of the screen. Click on the latitude-longitude, which will load a panel from which you can copy and paste the coordinates.

Requirements

Complete the classes described below. Place all classes in package hw6.

Main

Write class Main with a main method, which you are encouraged to use to test your code. Nothing in particular is required of it, but it must exist.

Waypoint

Write class Waypoint with the following methods:

Leg

Write class Leg that represents one stretch of an A-route. It encapsulates a named collection of waypoints and has the following methods:

Aroute

Write class Aroute that represents an A-route. It encapsulates a collection of legs and has the following methods:

ArtistCatalog

Write class ArtistCatalog that represents a collection of A-routes organized by their artists. This class is meant to act as an array that is indexed not by an integer, but by an artist name. To retrieve all A-routes designed by artist Footographer, for example, we’d write catalog.get("Footographer").

We recommend you implement this class using two parallel lists: one for artist names and the other for the A-routes designed by the artist that appears in the corresponding slots of the artist names list. In future courses you will learn of implementations that make better use of memory and the CPU using a technique called hashing.

This class has the following methods:

Utilities

Write class Utilities with the following method:

Extra

For an extra credit participation point, create an A-route file for a run of your own design. Share your file and screenshot of it from Google Earth or Google Maps on Piazza under folder ec6 by the due date. The submission garnering the most votes will be honored in some way.

Submission

To check your work and submit it for grading:

  1. Run the SpecChecker by selecting hw6 SpecChecker from the run configurations dropdown in IntelliJ IDEA and clicking the run button.
  2. Fix problems until all tests pass.
  3. Commit and push your work to your repository.
  4. Verify on GitLab that your submission uploaded successfully.

A passing SpecChecker does not guarantee you credit. Your grade is conditioned on a few things: