/******************************************************************* * * DESCRIPTION: This class holds data surrounding the completion * dates and rates of speed for a thru hike * * AUTHOR: Tom Janofsky * * HISTORY: 0.1 Initial version. * 0.2 Modify to allow different distances for section hikes, other hikes * * DATE:11/29/1999 * * Copyright (C) 1999 Tom Janofsky * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * *******************************************************************/ import java.util.Date; import java.text.DateFormat; import java.text.NumberFormat; /** This class provides a set of methods and data related to AT Thruhike completion. It tries to do the right thing when setting data and change the appropriately impacted data. * * @version 0.1 */ public class ATThruHikeData { /** Date the hike is to be started */ private Date startDate; /** Date to end hike */ private Date endDate; /** Length of hike */ private double length; /** How many 0 mile days */ private int daysOff = 0; /** How many miles hiked per day */ private double milesPerDay; /** Constructor requires a start date and estimated mileage * * @param start Date hike will be started * @param MilesPerDay Average miles per day */ public ATThruHikeData ( Date start, double MilesPerDay, double lengthOfHike){ startDate = new Date(start.getTime()); milesPerDay = MilesPerDay; length = lengthOfHike; calcEndDate(); } /** Returns the starting date * */ public Date getStartDate(){ Date retDate = new Date(startDate.getTime()); return retDate; } /** Changes the strarting date. This also changes the ending date * * @param newStart */ public void setStartDate(Date newStart){ startDate = new Date(newStart.getTime()); calcEndDate(); } /** Returns the ending date * */ public Date getEndDate(){ Date retDate = new Date(endDate.getTime()); return retDate; } /** Changes the ending date - this also affects the miles per day * * @param newEnd */ public void setEndDate(Date newEnd){ endDate = new Date(newEnd.getTime()); calcMilesPerDay(); } /** this returns the number of days scheduled off * */ public int getDaysOff(){ return daysOff; } /** This sets this the number of days scheduled to take off, and affects the ending date. * * @param newDays */ public void setDaysOff(int newDays){ daysOff = newDays; calcEndDate(); } /** This returns the miles estimated per day * */ public double getMilesPerDay(){ return milesPerDay; } /** This changes the number of estimated miles per day, and affects the ending date * * @param newMiles */ public void setMilesPerDay(double newMiles){ milesPerDay = newMiles; calcEndDate(); } /** This private method recalculates the ending date * */ private void calcEndDate() { double daysNeeded = (length / milesPerDay) + daysOff; //convert that to milliseconds //daysNeeded * 24 hours in a day * 60 minutes in hour * 60 sec in a min * 1000 milli in a second long millisNeeded = (long) daysNeeded * 24 * 60 * 60 * 1000; endDate = new Date(startDate.getTime() + millisNeeded); } private void calcMilesPerDay(){ long timeAllottedMillis = endDate.getTime() - startDate.getTime(); long timeAllottedDays = timeAllottedMillis / 1000 / 60 / 60 / 24; timeAllottedDays += daysOff; milesPerDay = length / timeAllottedDays; } public void display(){ DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(1); System.out.print("Start on: " + df.format( this.getStartDate() ) ); System.out.print("\tDo " + nf.format( this.getMilesPerDay() ) + " miles per day."); System.out.print("\tTake " + this.getDaysOff() + " days off."); System.out.print("\tEnd on " + df.format( this.getEndDate() ) ); System.out.println(""); } }