6 Replies - 11657 Views - Last Post: 03 May 2012 - 08:18 PM Rate Topic: -----

#1 Jagst3r15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 21-December 10

Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:01 PM

So this is embarrassing, but I needed to re-do a lab since my teacher lost it and I deleted the file! :( I would appreciate any guidance. I think the title is self explanatory , so I am pretty much stuck with some of my math and am getting an error - it says it cannot find symbol 'convert' on line 13?

Here is my code:

import java.util.Scanner;

public class convertMillis {
	public static void main(String[] args) {

	long seconds, minutes, hours;

	Scanner input = new Scanner(System.in);

	long milliseconds = 0;
	System.out.print("Enter an amount in miliseconds:");
	milliseconds = input.nextLong(); 
	String time = convert(milliseconds);
	System.out.print(time);

  }
	public static String convertMillis(long milliseconds){
	   long seconds, minutes, hours;
	   seconds = milliseconds / 1000;
	   hours = seconds / 3600;
	   seconds = seconds % 3600;
	   seconds = seconds / 60;
	   minutes = minutes % 60;

       return("Your conversion is: " + seconds + ":" + minutes + ":" + hours);
  }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Convert milliseconds to hours, minutes, and seconds

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:06 PM

There is a procedure called convertMillis. There isn't a procedure called convert. Try replacing the call to convert with convertMillis
Was This Post Helpful? 1
  • +
  • -

#3 Jagst3r15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 21-December 10

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:11 PM

Thanks a bunch Dimitri :). I am now getting an error: variable minutes might not have been initialized. I am pretty sure i declared minutes though, right?
Was This Post Helpful? 0
  • +
  • -

#4 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:14 PM

You have never given minutes a value in that code.
long seconds, minutes, hours;  
seconds = milliseconds / 1000;  
hours = seconds / 3600;  
seconds = seconds % 3600;  
seconds = seconds / 60;  
minutes = minutes % 60;  


Do you see minutes with a value? You try to modulo an empty long. I don't think that is right.
Was This Post Helpful? 1
  • +
  • -

#5 Jagst3r15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 21-December 10

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:17 PM

This better?

public static String convertMillis(long milliseconds){
long seconds, minutes, hours;
   seconds = milliseconds / 1000;
   minutes = seconds / 60;
   seconds = seconds % 60;
   hours = minutes / 60;
   minutes = minutes % 60;

        return("Your conversion is: " + hours + ":" + minutes + ":" + seconds);
      }


Was This Post Helpful? 0
  • +
  • -

#6 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 584
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:18 PM

Is it working for you?
Was This Post Helpful? 0
  • +
  • -

#7 Jagst3r15  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 77
  • Joined: 21-December 10

Re: Convert milliseconds to hours, minutes, and seconds

Posted 03 May 2012 - 08:18 PM

Yea it worked don't know why I asked if it's better hehe :P. Thanks for the help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1