lookadistraction
2008-09-28 22:50:34 UTC
The time is valid. or The time is invalid.
Finally, it needs a getTime() method to show the time in the format shown:
The time is 3:45:00
Write a separate ClockTestDrive class to:
* create an instance of a Clock
* set the hours, minutes, and seconds to random (but valid) numbers
* verify the validity of the time using checkTime()
* show the time using getTime()
i am having trouble making it so that i prints out correctly right now i prints out 1:045:7
here are my two files
class Clock
{
int hour;
int min;
int sec;
String col = ":";
String zero = "0";
void checkTime( )
{
if ( hour>0 && min<=59 && sec<=59 )
{
System.out.println( "The time is valid." );
}
else
{
System.out.println( "The time is invalid." );
}
}
void time( )
{
if (min<10 || sec<10 )
{
System.out.println( hour + col + zero + min + col+ zero + sec);
}
else
{
System.out.println( hour + col + min + col + sec );
}
}
}
and
class ClockTestDrive
{
public static void main( String[] args )
{
Clock a = new Clock();
a.hour = ( int )( Math.random( )*12 );
a.min = ( int )( Math.random( )*59 );
a.sec = ( int )( Math.random( )*59 );
a.time( );
a.checkTime( );
} //end main
} //end class ClockTestDriv
when i do this it keeps on making that mistake. i might be able to use a while statement not sure if i can