Results 1 to 6 of 6
- 02-13-2011, 09:03 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 11
- Rep Power
- 0
So I'm supposed to convert seconds to hours...
I went to class yesterday and the teacher says you should be on each lab for about 30 minutes and you should be done, but it takes me at least 4-5 hours to get everything together... I'm doubting whether this is right for me...I like working on this but man I take too much time?
having said that, I'm having problems dividing seconds into hours to get it in the standard time format and the am/pm time format. It looks easy, since you divide 60 by the seconds entered to get hours, divide by 60 again to get the minute then again to get seconds...but it comes out weird?
1. Divide the seconds entered by the user by the number of seconds in an hour
(SECONDS_X_HOUR), the result will be the hours in standard time.
2. Compute the remainder of seconds entered by the user by the number of seconds
in an hour (SECONDS_X_HOUR).
3. Divide the remainder obtained in the previous step by the number of seconds in a
minute (SECONDS_X_MINUTE), the result of this division will be the minutes.
4. The remainder of this last division will be the seconds.and here's what I've come with, and there is an error on the standardMinute and standardSecond wit the % (Syntax error). at first I just divided the standardHour by seconds_x_minute and standardminute by seconds_x minute but number for hours, minutes and seconds come out the same (figured I pretty much divided the same number for all 3 cases but i'm not too sure). Also I'm not even sure if I'm using the correct data type?int SECONDS_X_HOUR = 3600;
int SECONDS_X_MINUTE = 60;
int AM_PERIOD = 43199;
System.out.print("Please enter the time in seconds: ");
long Answer = keyboard.nextLong();
if (Answer < 0){
System.out.println("You must enter a number bigger than 0!");
}
else {
// Standard Format
double standardHour = (Answer / SECONDS_X_HOUR);
double standardMinute = ((standardHour%) /SECONDS_X_MINUTE);
double standardSecond = ((standardMinute%) / SECONDS_X_MINUTE);
System.out.println("Standard Format: " + standardHour + "h., " + standardMinute + "m., " + standardSecond + "s.");
- 02-13-2011, 09:08 PM #2
Senior Member
- Join Date
- Aug 2010
- Posts
- 127
- Rep Power
- 0
As far as I know, your only mistake is in the use of the '%'-operator, do you know how that operator works, what it does?
- 02-13-2011, 09:10 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 11
- Rep Power
- 0
remainder, supposed to take the remainder of the divided number between the x % y, isn't it? also sometimes the answer comes out to be a loooong decimal, thinking about it now I'm not sure if decimals should happen at all... is that right?
ohohhhh i got it thanks I was on this lab for like 4 hours now and was really frustrated :< confused the definition of remainder with the decimal points you get when you divide with like a calculator or somethingLast edited by nope; 02-13-2011 at 09:16 PM.
- 02-13-2011, 09:29 PM #4
Senior Member
- Join Date
- Jan 2011
- Location
- Belgrade, Serbia
- Posts
- 227
- Rep Power
- 3
So is it working now?
- 02-13-2011, 09:48 PM #5
Member
- Join Date
- Feb 2011
- Posts
- 11
- Rep Power
- 0
At least that part, yes, working on figuring out the AM/PM part now.
Got everything but the last part: The supposed answer should have returned without any decimals, but I see .0 after all the hr/min/sec. I haven't learned about math.round nor BigInteger yet and I vaguely remember %2 or something like that (formatter apparently), how do I set it up so no decimals show? "%.2f" is supposed to be with 1 decimal place, isn't it?Last edited by nope; 02-13-2011 at 11:18 PM.
- 02-13-2011, 11:46 PM #6
Similar Threads
-
Finding epoch seconds and separate yera,month,day,hr,min and seconds
By sathish kumar in forum New To JavaReplies: 4Last Post: 09-09-2010, 11:15 AM -
small method isn't supposed to go under 0
By senca in forum New To JavaReplies: 2Last Post: 08-09-2010, 01:23 PM -
a constructor to convert seconds to hours, min & seconds
By senca in forum New To JavaReplies: 3Last Post: 04-05-2010, 01:08 PM -
Convert microseconds to seconds
By Basit56 in forum New To JavaReplies: 4Last Post: 12-31-2009, 05:54 AM -
Help interpreting what a class is supposed to do
By bornwithnoname in forum New To JavaReplies: 2Last Post: 11-20-2008, 12:19 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks