1. 요구사항
- 12시간 시계를 만들 것. 형식은 아래 그림처럼.
24시간 시계 프로그램 정보
|
추가 조건 정수형 타입만 사용할 것!!
- 1) 표준시간대를 사용할 것.
- mills 부터 시작해 hour까지 %(mod), / (divde), int casting의 관계를 이용할 것.
3. 디자인
- 1) 함수 설정
- 함수 타입 - Void
- parameter - 정수
(최초 작성일 9.18일)
updata내역
import java.util.Scanner; public class Homework2CurrentTIme { public static void main(String[] args) { long milliseconds; long seconds, currentSeconds; long minutes, currentMinutes; long hours, currentHours; milliseconds = System.currentTimeMillis(); seconds = milliseconds / 1000; currentSeconds = seconds % 60; minutes = seconds / 60; currentMinutes = minutes % 60; hours = minutes / 60; currentHours = hours % 24; System.out.println("GMT Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds); Scanner input = new Scanner(System.in); System.out.print("Enter the time zone offset to GMT: "); int time = input.nextInt(); hours = hours + time; long ampm = hours / 12; if(ampm%2 == 0){ currentHours = hours % 12; System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "AM"); } else{ currentHours = hours % 12; if(currentHours==0){ currentHours = currentHours + 12; System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "PM"); } else{ System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "PM"); } } } }Updata 10.10일 함수화시키기
import java.util.Scanner; public class Homework2CurrentTIme { static void TimezoneOffset(){ long seconds, currentSeconds; long minutes, currentMinutes; long hours, currentHours; long milliseconds; milliseconds = System.currentTimeMillis(); seconds = milliseconds / 1000; currentSeconds = seconds % 60; minutes = seconds / 60; currentMinutes = minutes % 60; hours = minutes / 60; currentHours = hours % 24; System.out.println("GMT Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds); Scanner input = new Scanner(System.in); System.out.print("Enter the time zone offset to GMT: "); long time = input.nextInt(); currentHours = currentHours + time; long ampm = currentHours / 12; if(ampm%2 == 0){ currentHours = currentHours % 12; System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "AM"); } else{ currentHours = currentHours % 12; if(currentHours==0){ currentHours = currentHours + 12; System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "PM"); } else{ System.out.println("The Current time is " + currentHours + ":" + currentMinutes + ":" + currentSeconds + "PM"); } } } public static void main(String[] args) { TimezoneOffset(); } }5. 고찰
1) 함수형대로 바꿔볼 것
2) 클린 코드에 대해 알아보고 클린 코드지향적 프로그램 수정후 다시 업로드.
System.currentTimeMillis()에 대해 조사
댓글 없음:
댓글 쓰기