时钟走动
package day20150430;
/**
* 时钟走动
* @author 谷振东
*
*/
public class Clock {
private int hour;
private int minute;
private int second;
/**
* 走起来
*/
public void go(){
second += 1;
if (second ==60) {
second = 0;
minute += 1;
if (minute == 60) {
minute = 0;
hour += 1;
if (hour == 24) {
hour = 0;
}
}
}
}
/**
* 显示时间
*/
public void display(){
System.out.println(hour + ":" + minute + ":" + second );
}
public void setHour(boolean up){
if (up) {
hour += 1;
if(hour == 24){
hour = 0;
}
}
else {
hour -= 1;
if (hour == -1) {
hour = 23;
}
}
}
public void setMinute (boolean up){
if (up) {
minute += 59;
if(minute == 59){
minute = 0;
}
}
else {
minute -= 1;
if(minute == -1){
minute = 59;
}
}
}
public void setSecond(boolean up){
if (up) {
second += 59;
if (second == 59) {
second = 0;
}
}
else {
second -= 1;
if (second == -1) {
second = 59;
}
}
}
}
鬼怪抽象类
package day20150430;
/**
* 鬼怪
* @author 谷振东
*
*/
public class Ghost {
double top;
String color;
/**
* 飞
* @param fly 飞行
*/
public void fly (String fly ){
System.out.println("飞起来了。"+ fly);
}
/**
* 跳
* @param jump 跳跃
*/
public void jump (String jump){
System.out.println("跳"+ jump);
}
}