i have hard time doing this program.a example i have to is a string returning as hours:minutes:s econds, like convertMillis(5 500) returns a string 0:0:5, convertMillis(1 00000) returns a string, 0:140:. and convertMillis(5 55550000) 154:19:10. i am like having a brain bust lately and cant figure how to come make one and compile.Anyone help me? i have to make millseconds to hours:minutes:s econds
Help with convertMills
Collapse
X
-
Converting Milliseconds to Time
import java.util.*;
public class hw_6 {
public static void main(String[] args){
}
public static void convertMillis(l ong millis){
System.out.prin t("How much Millseconds ");
long Millis =0;
long time = Millis / 1000;
int seconds = ((int)(time % 60));
int minutes = ((int)((time % 3600) / 60));
int hours = ((int)(time / 3600));
}
}
okay i got part of it right i think. i am trying prompt user to end amount of milliseconds so that it will convert into time.
in this fromat(hh:mm:ss . please help me as quickly as possible please. the more i understand then better. -
Do you care about rounding, or are you just rounding down?
Are you going smallest units to biggest units, or the other way around?
eg. smallest first:
5500ms / 1000 => 5 seconds
100000ms / 1000 => 100 seconds
100 seconds is bigger than 60 secs (in a minute), so count the number of minutes too.
Code would helpComment
-
mport java.util.*;
public class hw_6 {
public static void main(String[] args){
}
private static String convertMillis(l ong millis) {
System.out.prin t("How much Millseconds ");
long time = millis / 1000;
int seconds = ((int)(time % 60));
int minutes = ((int)((time % 3600) / 60));
int hours = ((int)(time / 3600));
return convertMillis(0 ) ;
}
private static final StringBuilder(S tring convertedTime){
return convertedTime.t oString();
StringBuffer sb = new StringBuffer();
sb.append(hours );
sb.append(":");
sb.append(minut es);
sb.append(":");
sb.append(secon ds);
String s = sb.toString();
}
{
}
}
this what i got so far? did i do something wrong? or am i missing something. and do i need to add a assert ..:..:..".equal s(convertMillis (....) into it?Comment
-
This is good so far. Now you just need to organize your code to call each other properly.
and in your main, you'd have something like (pseudocode):Code:private static String convertMillis(long millis) { ... ... int hours = ((int)(time / 3600)); //create return string. StringBuffer sb = new StringBuffer(); sb.append(hours); ... ... return sb.toString(); }
Code:public static void main(String[] args){ System.out.println("How much Millseconds "); get millis from input. System.out.println(convertMillis(millis) ); }Comment
-
import java.util.*;
public class hw_6 {
public static void main(String[] args){
System.out.prin tln("How much Millseconds ");
get millis; from input;
System.out.prin tln(convertMill is(millis) );
}
//return string
private static String convertMillis(l ong millis) {
StringBuffer sb = new StringBuffer();
sb.append(hours );
sb.append(":");
sb.append(minut es);
sb.append(":");
sb.append(secon ds);
return sb.toString();
long time = millis / 1000;
int seconds = ((int)(time % 60));
int minutes = ((int)((time % 3600) / 60));
int hours = ((int)(time / 3600));
return convertMillis(0 ) ;
}
private static final StringBuilder(S tring convertedTime){
return convertedTime.t oString();
}
i dont know if that is what you mean by more organized. i am still getting errors. for example.
private static final StringBuilder(S tring convertedTime){ <-- there it says i cant find the return string and stuff
i get errors on the pseudocode.Comment
Comment