⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 time2.java

📁 《Java面向对象程序设计》例子源代码.轻松学习书本.
💻 JAVA
字号:
//Time2.java
import java.text.DecimalFormat;  
public class Time2 {
   private int hour; 
   private int minute; 
   private int second;   
   public Time2(){ 
      setTime( 0, 0, 0 ); 
   }
   public Time2( int h, int m, int s ){ 
      setTime( h, m, s ); 
   }
   public void setTime( int h, int m, int s ){		//setTime方法
      setHour( h );   
      setMinute( m ); 
      setSecond( s ); 
   }
   public void setHour( int h ){ 				//setHour方法
      hour = ( ( h >= 0 && h < 24 ) ? h : 0 ); 
   }
   public void setMinute( int m ){ 			//setMinute方法
      minute = ( ( m >= 0 && m < 60 ) ? m : 0 ); 
   }
   public void setSecond( int s ){ 			//setSecond方法
      second = ( ( s >= 0 && s < 60 ) ? s : 0 ); 
   }
   public int getHour(){ 					//getHour方法
      return hour; 
   }
   public int getMinute(){ 					//getMinute方法
      return minute; 
   }
   public int getSecond(){ 					// getSecond方法
      return second; 
   }
   public String toUniversalString(){
      DecimalFormat twoDigits = new DecimalFormat( "00" );
      return twoDigits.format( getHour() ) + ":" +
         twoDigits.format( getMinute() ) + ":" +
         twoDigits.format( getSecond() );
   }
   public String toStandardString(){
      DecimalFormat twoDigits = new DecimalFormat( "00" );
      return ( ( getHour() == 12 || getHour() == 0 ) ? 
         12 : getHour() % 12 ) + ":" + twoDigits.format( getMinute() ) +
         ":" + twoDigits.format( getSecond() ) + 
         ( getHour() < 12 ? " AM" : " PM" );
   }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -