Class DecimalConverter

Object
DecimalConverter
All Implemented Interfaces:
Converter

public class DecimalConverter extends Object implements Converter
This class converts DecimalCoordinate objects to DMSCoordinate objects. This class should be constructed with a DecimalCoordinate object. Once that object is set, convert() can be called to convert the decimalObj to a DMSCoordinate object and set it appropriately.
  • Field Details

    • decimalObj

      DecimalCoordinate decimalObj
      The DecimalCoordinate object to be converted.
    • convertedObj

      DMSCoordinate convertedObj
      Once convert() is called, this convertedObj is set to the correct DMSCoordinate.
  • Constructor Details

    • DecimalConverter

      public DecimalConverter()
      Default constructor to assign decimalObj to 0.
    • DecimalConverter

      public DecimalConverter(DecimalCoordinate decimalObj)
      Overloaded constructor which takes in a pre-existing DecimalCoordinate object and sets decimalObj equal to it.
      Parameters:
      decimalObj - DecimalCoordinate object with values already set.
  • Method Details

    • getConvertedObj

      public DMSCoordinate getConvertedObj()
      Returns convertedObj.
      Returns:
    • convert

      public void convert()
      Implements the convert() method from the Converter interface. Should take the decimalObj and convert that to a DMSCoordinate, once converted, set convertedObj to the new DecimalCoordinate. The Math.floor() function will come in handy! There is some more information in the Additional Info section of the README. Math.floor() also returns a double, so to convert from double to int use the `(int)` cast before a double to "cast" it to an int.

      When creating and setting the convertedObj, I would recommend to use the DMSCoordinate(int, int, int, int, int, int) constructor. A helpful graphic of the formula in action is in the GitHub README, and a link to an explanation is available in the README.

      Specified by:
      convert in interface Converter