/*
 * TimeFormat.java (Formats time with smallest unit being 100th of                      
 *                  a second)
 *
 * Written by : Nitin Motgi   (nmotgi@cs.ucf.edu)
 *
 * Formats the time given in hundreds of seconds to hh:mm:ss.xx.
 * and also formats the percentages of the display.
 *
 * Portions copyright (c) 2001 to School of Electrical Engineering and 
 * Computer science, UCF.
 *
 * Use and distribution of this source code are strictly governed by
 * terms and condition of the author.
 *
 * $Id : TimeFormat.java,  v1.0 02/04/2001. $
 *
 * Revision History. 
 * 1. Created Basic Method,            $Id: v1.0.0      02/04/2001.
 * 2. Added Documentation,             $Id: v1.0.1      02/04/2001. 
 * 3. Added formatTime                 $Id: v2.0.0      02/04/2001.  
 * 4. Added formatPercent              $Id: v2.1.0      02/05/2001. 
 * 5. Modified Documentation,          $Id: v2.1.1      02/05/2001. 
 * 6. Final Documentation Check,       $Id: v2.1.2      02/06/2001. 
 * 7. Final Variable name Check,       $Id: v2.1.3      02/06/2001. 
 * 8. Final Functionality Check,       $Id: v2.1.4      02/06/2001. 
 *
*/

public class TimeFormat{

   /************************************************************************
    * Default constructor.
    */
   public TimeFormat(){  
   }/* End of default constructor.*/

   /*************************************************************************
    * Formats the long time into string with hh:mm:ss.ns.
    */
   public String formatTime(long lTime){
    long LeftSec=0;
    long LeftMin=0;
    int  nHour=0,nMin=0,nSec=0,nHundSec=0;
    String szTime = new String();

    LeftSec   = lTime/100;
    nHundSec  = (int)(lTime%100);
    LeftMin   = LeftSec/60;
    nSec      = (int)(LeftSec%60);
    nMin      = (int)(LeftMin%60);
    nHour     = (int)(LeftMin/60);
    
    if(nHour == 0 && nMin == 0 && nSec == 0)
     szTime = "0."+nHundSec;
    else
     if(nHour == 0 && nMin == 0)
      szTime = nSec + "." + nHundSec;
     else
      if(nHour == 0)
       szTime = nMin + ":" + nSec + "." + nHundSec;
      else
       szTime = nHour + ":" + nMin + ":" + nSec + "." + nHundSec;
    return szTime;
   }/* End of formatTime.*/

   /*************************************************************************
    * Formats Percentage to String takes float number as parameter.
    */
   public String formatPercent(float rNumber){
    String szNumber = new String();
    int nNumber = (int)(rNumber * 100);
    int nLeftNumber  = nNumber/100;
    int nRightNumber = nNumber%100;
    /* This method is used for truncation.*/
    if(nRightNumber >= 50) nLeftNumber++;
    szNumber = nLeftNumber + "";
    return szNumber;
   }/* End of formatPercent.*/

   /*************************************************************************
    * Formats Percentage to String takes double number as parameter.
    */
   public String formatPercent(double rNumber){
    String szNumber = new String();
    int nNumber = (int)(rNumber * 100);
    int nLeftNumber  = nNumber/100;
    int nRightNumber = nNumber%100;
    /* This method truncates the based on numbers after decimal points.*/
    if(nRightNumber >= 50) nLeftNumber++;
    szNumber = nLeftNumber + "";
    return szNumber;
  }/* End of formatPercent.*/

}/* End of TimeFormat.*/
    

