Due: Sept 22nd @ 10:00 pm
Purpose:
To practice designing classes: turning problem and data descriptions into Java class/interface definitions.
Note: You'll need to setup Eclipse as we did in Lab #2. Follow those directions if you haven't already done so.
Place all of your code for the main problems (not including practice problems) in a single file, Assignment_02.java. In the future we may use multiple files, but for now, this will make your lives easier during the submission and grading process.
Practice Problems (Not Graded):
HtDCH Exercises: 2.5, 3.1, 4.3, 5.3, 6.1, and 6.7Programming Problem 1: (BookProblems)
Solve the following HtDCH problems as complete programs (i.e., class definitions and examples). Be sure to put your names at the top in a comment, and mark off problem numbers within the file.
Important: Place all your examples in a single class, BookProblemExamples, separated by blank lines, in order to make your file easier to grade.
- Exercise 2.4 on page 17,
- Exercise 4.4 on page 34,
- Exercise 4.6 on page 35,
Note that for Exercise 4.4, the program need not modify balances according to interest, but simply hold the values for the different fields.
Programming Problem 2: (Cities)
Your task is to design data definitions that represent a City for a mapping program (we'll build on this for a later assignment, so make sure you do a good job).
Place these definitions below the Book Problems, separated by blank lines and a block comment for the problem.
- Design a class to represent Locations in latitude and longitude coordinates. For example, Boston is located at (42.35, -71.06), where the first number is latitude, and the second is longitude.
- The cities.txt file contains definitions of the U.S. capital cities... use the numbers to create some example locations.
- Design a class to represent a City. A city has a name, a state, and a location.
- You should now be able to represent a few of the Cities from cities.txt... do so now.
- Design an interface and classes to represent lists of Cities. Name them ILoC, MtLoC, and ConsLoC, just for consistency.
- Make some examples of lists using the cities you created before.
Extra credit:
We've only just begun to explore methods and libraries... so this is a little extra fun. Grab the JavaWorld JAR (a Java Library written to provide all the features of Racket's Univers package... and more!). Save it in your workspace, and add it to your Project (right-click on the Project, select Build Path > Configure Build Path..., go to the Libraries tab and Add External Jars).
We've thrown together a little Map class that you can use to load map images of any latitude/longitude on Earth. It uses Google Static Maps (and a few JavaWorld classes).
Import the Maps.java file into your project (copy it into the right folder then right-click your project and select Refresh ... or just select import in the Eclipse file menu).
Take a look at Map.java. In particular, see what is required to construct a new Map instance, then work out the following:
- Design a method toMap() inside your City class that returns a correctly named Map of the city... use the name of the city as the title, and its location (lat/lon) for the... well, location. Make the map be 200 x 200 or something.
- Add an example that uses World.display to load/display the map of a city. Something like the following should work... just make sure you have an Internet connection before you run it:
// Feel free to add the body to another Examples class too class DisplayExamples{ City boston = new City("Boston", "Massachusetts", new Location(42.35, -71.06)); boolean res = world.World.display(this.boston.toMap().getImage()); }- Try it out with a few different cities... here's two samples for Boston and Albany, one shown with a marker, the other without:
Feel free to explore a little more if you have time. This is but a taste of what we'll be able to do in the next few weeks!!