标题:[求助]为什么会这样
只看楼主
光明左使
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-8-16
 问题点数:0 回复次数:5 
[求助]为什么会这样

我编了一个包Time2,并用TimeTest4来调用,可是在调用的过程中,却出现了点问题,请高手支招.
TimeTest4.java如下:
import javax.swing.*;
import c.czg.Time2;

public class TimeTest4 {
public static void main ( String args[] )
{
Time2 t1,t2,t3,t4,t5,t6;

t1 = new Time2 ();
t2 = new Time2 ( 2 );
t3 = new Time2 ( 21,34 );
t4 = new Time2 ( 12,25,42 );
t5 = new Time2 ( 27,74,99 );
t6 = new Time2 ( t4 );

String output = "Constructed with:" +
"\nt1: all arguments defaluted" +
"\n " + t1.toUniversalString() +
"\n " + t1.toString();

output += "\nt2:hour specified;minute and " +
"second defaluted" +
"\n " + t2.toUniversalString() +
"\n " + t2.toString();

output += "\nt3:hours,minute,and specified" +
"\n " + t3.toUniversalString() +
"\n " + t3.toString();

output += "\nt4:hours,minute,second specified" +
"\n " + t4.toUniversalString() +
"\n " + t4.toString();

output += "\nt5:all invalid values specified" +
"\n " + t5.toUniversalString() +
"\n " + t5.toString();

output += "\nt6:Time2 object t4 specified " +
"\n " + t6.toUniversalString() +
"\n " + t6.toString();

JOptionPane.showMessageDialog( null,output,"Demonstrating Overloaded Contstuctors",
JOptionPane.INFORMATION_MESSAGE );

System.exit(0);
}
}
Time2.java如下:
package c.czg;

import java.text.DecimalFormat;

public class Time2 extends Object {
private int hour ;
private int minute ;
private int second ;

public Time2 ()
{
setTime ( 0, 0, 0);
}

public void setTime ( int h,int m,int s )
{
hour = ( ( h>=0 && h<24 )? h:0 );
minute = ( ( m>=0 && m<60 )? m:0 );
second = ( ( s>=0 && s<60 )? s:0 );
}

public String toUniversalString ()
{
DecimalFormat two = new DecimalFormat ( "00" );

return two.format ( hour ) + ":" +
two.format ( minute ) + ":" +
two.format ( second );
}

public String toString ()
{
DecimalFormat two = new DecimalFormat ( "00" );

return ( ( hour==12 || hour ==0 )? 12:hour%12 ) +
":" + two.format ( minute ) +
":" + two.format ( second ) +
( hour < 12 ? "AM" : "PM" );
}
}


搜索更多相关主题的帖子: new import public 
2006-10-25 12:57
しΟν∈→鱈
Rank: 1
等 级:新手上路
威 望:2
帖 子:369
专家分:0
注 册:2006-10-25
得分:0 
....虽然我不一定会,不过你连问题都没帖上来  别人怎么解决?

开开心心的过&玩每一天!!!!
2006-10-25 13:04
999hits
Rank: 1
等 级:新手上路
威 望:1
帖 子:227
专家分:0
注 册:2005-10-2
得分:0 
你的TimeTest4调用了Time2类的6个不同的构造函数,而你的Time2里只有一个构造函数

J3D的摸瞎人
2006-10-25 14:21
光明左使
Rank: 1
等 级:新手上路
帖 子:66
专家分:0
注 册:2006-8-16
得分:0 
有没有谁能给我一个详细的答案,指点迷津

以剑论道,以道搏剑,快意恩仇,却是何等的孤独!!
2006-10-26 12:37
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
以下是引用光明左使在2006-10-26 12:37:08的发言:
有没有谁能给我一个详细的答案,指点迷津

你楼上的已经讲得很清楚了


可惜不是你,陪我到最后
2006-10-26 13:22
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 
t1 = new Time2 ();
t2 = new Time2 ( 2 );
t3 = new Time2 ( 21,34 );
t4 = new Time2 ( 12,25,42 );
t5 = new Time2 ( 27,74,99 );
t6 = new Time2 ( t4 );
你调用了这么多个Time2的构造函数,你定义了几个呢?

可惜不是你,陪我到最后
2006-10-26 13:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-98612-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019797 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved