KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > sql > Time

java.sql
Class Time

java.lang.Object
  extended by java.util.Date
      extended by java.sql.Time
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Date>
See Also:
Top Examples, Source Code

@Deprecated
public int getDate()
See Also:
setDate(int), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1341]Tortoise Hare Race
By ralphjarvis { at } yahoo { dot } com on 2005/03/11 17:34:02  Rate
//program indicating a race between the hare and the tortoise 
 // 
 // 
 import java.sql.Time ;//program uses class Time 
 import java.util.Random; //program uses class Random 
  
  
  
 public class TortoiseHareRace  
  {  
   public static void main  ( String args [  ]  )  
    {  
     int tortoise; 
       int hare; 
       int timer=0; 
       int Random ( Time ( 0 )  ) ; 
       int RACE_END=70; 
        
        // set the random number generator seed 
         
       //getting ready to start the race 
        System.out.print ( "BANG !!!!\n" ) ; 
        System.out.print ( "\nAND THEY'RE OFF !!!\n" ) ; 
        
       //Control Race 
       while ( tortoise ! = RACE_END && hare != RACE_END )  
        {  
         //call for tortoise 
         moveTortoise.tortoise; 
          
         //call for hare 
         moveHare.hare; 
          
         //call for the printCurrentPositions 
         printCurrentPositions.tortoise; 
         printCurrentPositions.hare; 
         ++timer; 
          
         } // end while 
         
         
        //to determine winner 
        if  ( tortoise  > =hare )  
          {  
           
            System.out.println ( "TORTOISE WINS !!! YAY !!!\n" ) ; 
           }  
         else  
          {  
            System.out.println ( "HARE WINS. YUCH.\n" ) ; 
            System.out.println ( "TIME ELASPED = "seconds"\n" ) ;    
          }  
     } //end main 
     
   //return 0; 
        
    //move tortoise 
    public void moveTorise  (  int turtlePtr )  
     {  
      Random randomNumbers = new Random (  ) ; // random number generator 
         int x; // stores each random integer generated 
       
      //pick a random integer 
         x = 1 + randomNumbers.nextInt (  )  % 10; 
          
         //determine which move to make 
         if ( x > =1 && x < 5 )  //fast plod 
         // {  
           turtlePtr + =3; 
            
         else if ( x==6 || x==7 )  // slip 
              {  
               turtlePtr - =6; 
              } // end else if 
                       
         else 
            ++turtlePtr; 
             
             if  ( turtlePtr  < 1 )  
                    
          // } //outer if 
           
          if  ( turtlePtr  < 1 )  
           
              {  
              turtlePtr= 1; 
              } //end inner if 
              
           
         else if  ( turtlePtr  >  RACE_END )  
           {  
             turtlePtr = RACE_END; 
           }  // end else if 
  
  
     }  //end method moveTortise 
     
     
    //moveHare 
    public void moveHare (  int harePtr )  
     {  
       Random randomNumbers = new Random (  ) ; // random number generator 
          int y; // stores each random integer generated 
       
      //pick a random integer 
         y = 1 + randomNumbers.nextInt (  )  % 10; 
          
         //determine which move to make 
         if (  y > = 1 && y < =5 ) // fast plod 
          
           harePtr + =3; 
            
         else if  (  y==6 || y==7 ) // slip  
            {  
             harePtr - =6; 
            } // end else if   
            
         else 
            ++ harePtr; //slow plod 
             
                
           //ensures that the tortoise remains within subscript range 
        if ( harePtr  < 1  ) ; 
              {   
              harePtr = 1; 
              
              } //end if 
            
        else  ( harePtr  >  RACE_END )  
           // {  
             harePtr= RACE_END; 
              
          //  } //end else 
           
           
      } // end method moveHare 
      
     //output positions of animals 
      
     public void printCurrentPositions (  int bunnyPtr, int snapperPtr )  
      {  
        if  ( bunnyPtr==snapperPtr )  
         {  
          System.out.println (  ) ; 
         }  
         
        else if  ( bunnyPtr <  snapperPtr  )   
         {  
          System.out.println (  ) ; 
          }  
       } //end printCurrentPositions 
  } 


@Deprecated
public int getDay()
See Also:
Calendar, IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public int getMonth()
See Also:
setMonth(int), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public int getYear()
See Also:
setYear(int), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public void setDate(int i)
See Also:
getDate(), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public void setMonth(int i)
See Also:
getMonth(), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setTime(long time)
See Also:
Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public void setYear(int i)
See Also:
getYear(), IllegalArgumentException, Date
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


@Deprecated
public Time(int hour,
                       int minute,
                       int second)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Time(long time)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString()
See Also:
Date.toGMTString(), Date.toLocaleString()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static Time valueOf(String s)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags