CMSI 185
Homework #5
Due: 2009-04-23

In this assignment, you'll be writing your own classes, from scratch.

  1. Write a class called ArithmeticSequenceGenerator. An arithmetic sequence generator has at least two fields: start and delta. These two fields are set in the constructor, meaning that if a user invokes:
        ArithmeticSequenceGenerator g = new ArithmeticSequenceGenerator(10,7);
    
    then a sequence generator will be created with start value 10 and delta value 7. Both of these fields are private, and there are no getters and setters for them. There is one method, though, called next. For our example generator, g defined above, the first call to next() returns 10, then the next returns 17, then 24, etc.
  2. Write a class called ArithmeticSequenceGeneratorDemo which creates three different arithmetic sequence generators with different values, and writes, to System.out, the results of calling next() several times on each.
  3. Write a class for a point on the Earth's surface, with two fields, latitude and longitude. These values should be set in the constructor. In the constructor, include code to throw an IllegalArgumentException if the caller passes in out of range values for either the latitude or longitude. The two fields should have getters but not setters. Include a method called antipode which returns the point directly "opposite" the point on which the method is called. Also give a toString method which displays points like this:
        (43.211N, 76.28W)
        (1.2433S, 93.00E)
        (89.878S, 179.3W)
    
    For extra credit, add a method that returns the distance from the point to another point, along the Earth's surface, of course. This is sometimes called the "great circle distance". You are not expected to know the math behind this compuatation, but you are expected to look up an algorithm or incorporate someone else's existing code, remembering to give such a person credit. Hint: The method should be defined like this:
        public double distanceTo(Point p) {...}