我该如何回归时间;来自printDetails中的ClockDisplay()对象?

时间:2015-11-08 03:32:44

标签: java

我需要创建一个历史时刻对象,它返回<script type="text/javascript"> if(field1 = getCookie("field1")) document.myForm.field1.value = field1; if(field2 = getCookie("field2")) document.myForm.field2.value = field2; if(field3 = getCookie("field3")) document.myForm.field3.value = field3; if(field4 = getCookie("field4")) document.myForm.field4.value = field4; </script> 对象的时间,我想知道如何返回时间;来自ClockDisplay()对象?当我编译它时,它没有错误但是当我创建一个时间值为11:00的ClockDisplay()对象并且我创建一个ClockDisplay对象并且我检查它时,它返回一个空值当我HistoricalMoment

这是我的代码:

printDetails

这是我的printDetails:

/**
 * @return the time
 */
public ClockDisplay getTime()
{
    return time;
}

这是我的HistoricalMoment类:

/**
 * the print details of time and event
*/
public void printDetails()
{
System.out.println("At " + getTime() + "," + getEventName());
}

这是我的ClockDisplay类:

public class HistoricalMoment{

private String eventName;
private ClockDisplay timeOfEvent;
private ClockDisplay time;

public static final int MIDNIGHT_HOUR = 00;
public static final int MINUTE_ZERO = 00;

public static final int ELVENTH_HOUR = 11;
public static final int TWO_MINUTES = 02;
public static final int FORTY_MINUTES = 40;
public static final int NINTH_HOUR = 9;
public static final int FOUR_MINUTES = 04;

/**
 * Default Constructor
 */
public HistoricalMoment(){
    eventName = "untitled event";
    timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);

}

/**
 * @param nameOfTheEvent the name of the event; "untitled event" if the name of the event is null or ""
 */
public HistoricalMoment(String nameOfTheEvent){
    if ((nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
        eventName = "untitled event";
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }
    else {
        eventName = nameOfTheEvent;
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }

}

/**
 * @param the name and time of the event
 */
public HistoricalMoment(String nameOfTheEvent, ClockDisplay theTime)
{
    if ( (nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
        eventName = "untitled event";
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }
    else{
        eventName = nameOfTheEvent;
        timeOfEvent = theTime;
    }
}

/**
 * @return the time of event
 */
public ClockDisplay getTime()
{
    return timeOfEvent;
}


/**
 * @return the eventName;
 */
public String getEventName()
{
    return eventName;
}

/**
 * @return the time of the event incremented
 */
public void addMinuteToTimeOfEvent(){
    timeOfEvent.timeTick();
}

/**
 * the print details of time and event
 */
public void printDetails()
{
    System.out.println("At " + getTime() + "," + getEventName());
}

}

1 个答案:

答案 0 :(得分:0)

所以我经过一段时间的思考后想出来,我要做的就是调用timeOfEvent获取值以与ClockDisplay值一致。

这是我遇到问题的printDetails的编码。希望将来能帮助其他任何人。

public void printDetails()
    {
        System.out.println("At " + timeOfEvent.getTime() + ", " + eventName);
    }

以下是带有更正的HistoricalMoments类的完整编码:

public class HistoricalMoment{

private String eventName;
private ClockDisplay timeOfEvent;

public static final int MIDNIGHT_HOUR = 00;
public static final int MINUTE_ZERO = 00;

public static final int ELVENTH_HOUR = 11;
public static final int TWO_MINUTES = 02;
public static final int FORTY_MINUTES = 40;
public static final int NINTH_HOUR = 9;
public static final int FOUR_MINUTES = 04;

/**
 * Default Constructor
 */
public HistoricalMoment(){
    eventName = "untitled event";
    timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);

}

/**
 * @param nameOfTheEvent the name of the event; "untitled event" if the name of the event is null or ""
 */
public HistoricalMoment(String nameOfTheEvent){
    if ((nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
        eventName = "untitled event";
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }
    else {
        eventName = nameOfTheEvent;
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }

}

/**
 * @param the name and time of the event
 */
public HistoricalMoment(String nameOfTheEvent, ClockDisplay theTime)
{
    if ( (nameOfTheEvent == null) || (nameOfTheEvent.equals(""))){
        eventName = "untitled event";
        timeOfEvent = new ClockDisplay(MIDNIGHT_HOUR, MINUTE_ZERO);
    }
    else{
        eventName = nameOfTheEvent;
        timeOfEvent = theTime;
    }
}

/**
 * @return the time of the event incremented
 */
public void addMinuteToTimeOfEvent(){
    timeOfEvent.timeTick();
}

/**
 * the print details of time and event
 */
public void printDetails()
{
    System.out.println("At " + timeOfEvent.getTime() + ", " + eventName);
}

}