Commit c189abcf authored by mrsl2000's avatar mrsl2000

add logic package and logic test

parent 5b7ab442
package org.clock.logic;
public class ClockLogic {
private int hour;
private int minute;
private int second;
public ClockLogic () {
this.hour = 0;
this.minute = 0;
this.second = 0;
}
public ClockLogic (int hour, int minute, int second) {
this.hour = hour;
this.minute = minute;
this.second = second;
}
public void setClock(int hour, int minute, int second) {
this.hour = hour;
this.minute = minute;
this.second = second;
}
public void tik(int second) {
this.second += second % 60;
second = second / 60;
this.minute += second % 60;
second = second / 60;
this.hour += second;
if (this.second > 60) {
minute++;
this.second %= 60;
}
if (this.minute > 60) {
hour++;
this.minute %= 60;
}
if (this.hour > 24) {
this.hour %= 24;
}
}
public int getHour() {
return hour;
}
public int getMinute() {
return minute;
}
public int getSecond() {
return second;
}
}
package test;
import org.clock.logic.ClockLogic;
public class ClockLogicTest {
public static void main(String[] args) {
ClockLogic clockLogic = new ClockLogic(1,2,3);
System.out.println(clockLogic.getSecond() == 3);
System.out.println(clockLogic.getMinute() == 2);
System.out.println(clockLogic.getHour() == 1);
clockLogic.setClock(10,20,30);
System.out.println(clockLogic.getSecond() == 30);
System.out.println(clockLogic.getMinute() == 20);
System.out.println(clockLogic.getHour() == 10);
clockLogic.tik(1);
System.out.println(clockLogic.getSecond() == 31);
System.out.println(clockLogic.getMinute() == 20);
System.out.println(clockLogic.getHour() == 10);
clockLogic.setClock(10,20,0);
clockLogic.tik(100);
System.out.println(clockLogic.getSecond() == 40);
System.out.println(clockLogic.getMinute() == 21);
System.out.println(clockLogic.getHour() == 10);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment