Im back again...

Ok guys iv'e been bugging you all week for this probelm but ive figured it out thanks to your help.

I am just having one minor error when im printing out the code. I kno where the problem is but when i fix it it gives me an error. I am suppose to print out Military time and regular Am/Pm time next to it. It prints fine but for some reason the military time is the same as the regualr time. I know why this is happeneing and it is from the toUniversalString method i have. Well long story short here is my program with my methods and my program main.

Please help...

publicclass MilitaryTime

{

privateint hour;

privateint minute;

privateint second;

public MilitaryTime()

{

hour=0;

minute=0;

second=0;

}

public MilitaryTime(int hour,int minute,int second)

{

//this.setHour(hour);

//this.setMinute(minute);

//this.setSecond(second);

this.hour=hour;

this.minute=minute;

this.second=second;

}

public MilitaryTime(MilitaryTime t)

{

}

publicvoid setHour(int h)

{

if(h<0 || h>=24)

{

this.hour=00;

}

else

{

this.hour=h;

}

}

publicvoid setMinute(int m)

{

if(m<0 || m>=60)

{

this.minute=00;

}

else

{

this.minute=m;

}

}

publicvoid setSecond(int s)

{

if(s<0 || s>=60)

{

this.second=00;

}

else

{

this.second=s;

}

}

publicint getHour()

{

return hour;

}

publicint getMinute()

{

return minute;

}

publicint getSecond()

{

return second;

}

publicvoid tick()

{

this.second++;

if(this.minute==59)

{

this.hour=hour+1;

this.minute=this.minute-60;

}

if(this.second==60)

{

this.minute=minute+1;

this.second=this.second-60;

}

}

public String toUniversalString()

{

StringBufferbuffer;

buffer =new StringBuffer();

if(this.hour < 10)

buffer.append("0");

buffer.append(this.hour).append(":");

if(this.minute < 10)

buffer.append("0");

buffer.append(this.minute).append(":");

if(this.second < 10)

buffer.append("0");

buffer.append(this.second).append("");

return buffer.toUniversalString();

}

public String toString()

{

StringBufferbuffer;

String message="bl";

buffer =new StringBuffer();

if(this.hour==12)

{

message="pm";

}

elseif(this.hour>12)

{

this.hour=this.hour-12;

if(this.hour>=12)

{

message="pm";

}

else

{

message="am";

}

}

elseif(this.hour<12)

{

message="am";

}

if(this.hour < 10)

buffer.append("0");

buffer.append(this.hour).append(":");

if(this.minute < 10)

buffer.append("0");

buffer.append(this.minute).append(":");

if(this.second < 10)

buffer.append("0");

buffer.append(this.second).append("");

buffer.append(message);

return buffer.toString();

}

}

Here is main where i try and print military and universal...

import javax.swing.*;

publicclass TestMilitaryTime

{

publicstaticvoid main(String[]args)

{

String sHour=JOptionPane.showInputDialog(null,

"Input Hour:","Military Time",JOptionPane.QUESTION_MESSAGE);

int hour=Integer.parseInt(sHour);

String sMinutes=JOptionPane.showInputDialog(null,

"Input minutes:","Military Time",JOptionPane.QUESTION_MESSAGE);

int minutes=Integer.parseInt(sMinutes);

String sSeconds=JOptionPane.showInputDialog(null,

"Input seconds:","Military Time",JOptionPane.QUESTION_MESSAGE);

int seconds=Integer.parseInt(sSeconds);

MilitaryTime time=new MilitaryTime(hour,minutes,seconds);

time.setHour(hour);

time.setMinute(minutes);

time.setSecond(seconds);

System.out.println("The American time: "+""+"The Military Time");

System.out.println(time.toString()+" "+time.toUniversalString());

for(int i=1; i<=60; i++)

{

time.tick();

System.out.println(time.toString()+""+time.toUniversalString());

}

}

}

By the way i am incrementing the program by 1 second 60 times...

Any help please post.

[9380 byte] By [Progr@mera] at [2007-11-27 1:42:09]
# 1

When i compile this is the error i get.

MilitaryTime.java:123: cannot find symbol

symbol : method toUniversalString()

location: class java.lang.StringBuffer

return buffer.toUniversalString();

^

But when i change the return toUniversalString();

to return toString(); the error goes away.

Progr@mera at 2007-7-12 0:58:24 > top of Java-index,Java Essentials,New To Java...
# 2
anyone got a clue or should i not waste time wating?
Progr@mera at 2007-7-12 0:58:24 > top of Java-index,Java Essentials,New To Java...
# 3
change the line to return buffer.toString()
ChuckBinga at 2007-7-12 0:58:24 > top of Java-index,Java Essentials,New To Java...