본문 바로가기
2015 IT 웹 기반 개발자과정/JAVA

JAVA 시간 입출력

by 한여름밤의코딩 2015. 10. 28.
package java_week1;
 
public class MyClock {
  private int hour;
  private int minute;
  private int second;
public MyClock(int hour, int minute, int second) {
    super();
    this.hour = hour;
    this.minute = minute;
    this.second = second;
}
public int getHour() {
    return hour;
}
public void setHour(int hour) {
    this.hour = hour;
}
public int getMinute() {
    return minute;
}
public void setMinute(int minute) {
    this.minute = minute;
}
public int getSecond() {
    return second;
}
public void setSecond(int second) {
    this.second = second;
}
   
  public void printCurrentTime(){
      System.out.println("현재시각 :"+getHour()+"시"+getMinute()+"분"+getSecond()+"초");
  }
}
 
===================================================================
 
package java_week1;
 
public class MyClockTest {
    public static void main(String[] args) {
         MyClock clock = new MyClock(1, 30, 20);
         clock.printCurrentTime();
         MyClockTest test = new MyClockTest();
         test.changeTime(clock, 2, 40, 10);
         clock.printCurrentTime();
    }
    private void changeTime(MyClock clock, int hour, int minute, int second){
        clock.setHour(hour);
        clock.setMinute(minute);
        clock.setSecond(second);
        System.out.println("시간을 변경했습니다.");
         
    }
 
}

'2015 IT 웹 기반 개발자과정 > JAVA' 카테고리의 다른 글

JAVA 대소문자 변환하기  (0) 2015.10.28
JAVA 두 원 충돌 여부 알기  (0) 2015.10.28
JAVA 로또  (0) 2015.10.28
JAVA string과 string buffer 의 차이점  (0) 2015.10.27
JAVA Bubble Sort  (0) 2015.10.27