求教

秋霜凋枫_ 2014-09-21 09:55:06
1.封装一个时间类MyTime,包含一个构造器,3个私有成员变量hour、minute、second以及与它们相应的set和get方法。(如hour 有getHour和setHour方法,分别表示获得hour和设置hour)。并重写toString()方法(该方法描述对象,相当于自我介绍,格式如 下:public String toString() )。
2. 封装一个日期类MyDate,包含一个构造器,3个私有成员变量year、mouth和day以及它们相对应的set和get方法。并重写toString()方法。
3.创建一个FullTime类。其中包含一个MyTime类型的私有成员变量以及与之相对应的set和get方法.一个MyDate类型的私有成员变量以及相对应的set和get方法。并重写toString()方法。假定当前时间为2007年10月2日14点17分35秒,编写用户程序TestFullTime,用FullTime类设置时间为以上的时间,并打印。
...全文
273 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
姜小白- 2014-09-21
  • 打赏
  • 举报
回复
建议楼主看看 Date 类的源码 楼主需要的需求Date 都实现了,仿照着写就是了 很多东西可以拿过来直接用的

/**
     * Allocates a <code>Date</code> object and initializes it so that
     * it represents the instant at the start of the second specified
     * by the <code>year</code>, <code>month</code>, <code>date</code>,
     * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
     * in the local time zone.
     *
     * @param   year    the year minus 1900.
     * @param   month   the month between 0-11.
     * @param   date    the day of the month between 1-31.
     * @param   hrs     the hours between 0-23.
     * @param   min     the minutes between 0-59.
     * @param   sec     the seconds between 0-59.
     * @see     java.util.Calendar
     * @deprecated As of JDK version 1.1,
     * replaced by <code>Calendar.set(year + 1900, month, date,
     * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
     * month, date, hrs, min, sec)</code>.
     */
    @Deprecated
    public Date(int year, int month, int date, int hrs, int min, int sec) {
        int y = year + 1900;
        // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
        if (month >= 12) {
            y += month / 12;
            month %= 12;
        } else if (month < 0) {
            y += CalendarUtils.floorDivide(month, 12);
            month = CalendarUtils.mod(month, 12);
        }
        BaseCalendar cal = getCalendarSystem(y);
        cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
        cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
        getTimeImpl();
        cdate = null;
    }

ghx287524027 2014-09-21
  • 打赏
  • 举报
回复
这种题还是建议你自己动手写写,没你想得那么难

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧