who knows java?

Meaningful discussion outside of the potato gun realm. Projects, theories, current events. Non-productive discussion will be locked.
User avatar
Carlman
Staff Sergeant 2
Staff Sergeant 2
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Been thanked: 2 times

Thu Mar 13, 2008 6:41 am

Hey all,

i need some help with someone who knows a bit of java. Ive just started it in uni and having trouble getting a program to compile.

I need to make a program that can display 4220 seconds as hours:minutes:seconds and then skip a line then do the same for 2500seconds.

heres what i have so far:

/**
* Converts two different number of seconds to hours:minutes:seconds.
*
*/
public class TimeChanger
{
public static void main(String[] args)
{
int time = 4220;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println(“4220 seconds:" +hours ":" +minutes ":" +seconds);

int time = 2500;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println(“4220 seconds:" +hours ":" +minutes ":" +seconds);
}

}

im using blueJ as my editing tool and its coming up with an illegal character on the first print line.

any help would be much appreciated
Last edited by Carlman on Wed Mar 19, 2008 8:52 am, edited 1 time in total.
Image
Aussie spudders unite!!
User avatar
Carlman
Staff Sergeant 2
Staff Sergeant 2
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Been thanked: 2 times

Thu Mar 13, 2008 9:35 am

public class TimeChanger
{
public static void main(String[] args)
{
int time = 4220;
int hours = time / 3600;
int hoursRemainder = time % 3600;
int minutes = hoursRemainder / 60;
int minutesRemainder = hoursRemainder % 60;
int seconds = minutesRemainder;
System.out.println("4220 seconds: " +hours +":" +minutes +":" +seconds);

time = 2500;
hours = time / 3600;
hoursRemainder = time % 3600;
minutes = hoursRemainder / 60;
minutesRemainder = hoursRemainder % 60;
seconds = minutesRemainder;
System.out.println("2500 seconds: " +hours +":" +minutes +":" +seconds);
}

}

its all good i sorted it out in the end!

thanks to all who helped :roll: lol jokes :D
Image
Aussie spudders unite!!
User avatar
dewey-1
Sergeant 3
Sergeant 3
Posts: 1298
Joined: Wed Mar 28, 2007 10:24 am
Location: NE Wisconsin USA

Thu Mar 13, 2008 10:19 am

--
Last edited by dewey-1 on Sun Apr 20, 2008 1:04 pm, edited 1 time in total.
User avatar
jimmy101
Sergeant Major 2
Sergeant Major 2
United States of America
Posts: 3206
Joined: Wed Mar 28, 2007 9:48 am
Location: Greenwood, Indiana
Has thanked: 6 times
Been thanked: 18 times
Contact:

Thu Mar 13, 2008 11:02 am

So what was the error? The "smart quotes" in the println statements?
Image
keep_it_real
Specialist 3
Specialist 3
Posts: 320
Joined: Sat Dec 23, 2006 4:41 pm
Location: Bend, Oregon

Thu Mar 13, 2008 11:08 am

he just forgot a plus sign after hours and minutes.
User avatar
SpudUke5
Sergeant
Sergeant
Posts: 1099
Joined: Tue Sep 04, 2007 10:16 pm

Thu Mar 13, 2008 2:02 pm

This aint too hard, im doing if, while and for loops and i dont understand for loops too much but if and while arent really hard.

Now i know i can come to someone here if i need help :)
4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
User avatar
Carlman
Staff Sergeant 2
Staff Sergeant 2
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Been thanked: 2 times

Thu Mar 13, 2008 5:25 pm

yea the prob was i was defining the variables again which it didnt like and i foot to add the other parts of the string.

@ LikimysCrotchus5: I start loops today :D
Image
Aussie spudders unite!!
User avatar
SpudUke5
Sergeant
Sergeant
Posts: 1099
Joined: Tue Sep 04, 2007 10:16 pm

Thu Mar 13, 2008 5:42 pm

Well if you dont understand something, and i do, then give me a pm. We had the option of downloading jgrasp (java system and compiler i use) and i did so i can get some work done for school and also make programs to do math for me.

For example, i made a pythagorean theorem calculator that outputs the third side, instead of typing in a calculator. So it makes some work easier.

So if you want some programs for the hell of it, ill give you all the code.

P.S. For the keyboard reader, i usually give it a name besides reader, like Joe, makes programming sort of more fun :D
4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
User avatar
Carlman
Staff Sergeant 2
Staff Sergeant 2
Posts: 1618
Joined: Sat Nov 24, 2007 1:18 am
Location: Western Australia
Been thanked: 2 times

Thu Mar 13, 2008 11:18 pm

how far along are you in java LMC?

ive had about 3 lectures on it :D

i use BlueJ, it was developed by a university in the eastern states of aussie land and is sponsored by sun microsystems. Its basically an easy to use system and compiler.
yea thanks foe the offer of help might take you up on it later :wink:
Image
Aussie spudders unite!!
User avatar
SpudUke5
Sergeant
Sergeant
Posts: 1099
Joined: Tue Sep 04, 2007 10:16 pm

Fri Mar 14, 2008 12:07 am

Well i started this class in the beginning of my second semester so i have had almost 2 months i think.

I have this class for a semester so the farthest our teacher said we would get is to applets, which are like little internet advertizmetns, i think.

Yea and feel free to do pm me whenever, and your welcome :)
4SPC, My 4" piston 3" porting cannon
Memo:
Fix up copper cannon
Fix up 4SPC
Start Stirrup pump
Start Toolies piston bazooka
Post Reply