millisecond time conversion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Kuriii
    New Member
    • Apr 2007
    • 3

    #1

    millisecond time conversion

    Can anyone help me with creating this code in Java? PLEASE! Thanks in advance!

    Ask the user for the number of milliseconds, validate that it's not negative, and
    display the result, then ask if the user wants to convert another number
    (you may use a confirmation dialog, or you may allow input of 1 for yes
    and 2 for no). Keep converting milliseconds until the user chooses no.

    Example: (5500) should return 0:00:05 and convertMillis(1 00000) should return 0:01:40.

    except your result MUST be formatted so that minutes and seconds are always two digits
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    #2
    Do you want a complete code for this?
    unfortunately we dont supply that.
    If you want help,post the code you have tried.We will try to help.
    Good Luck.
    Originally posted by Kuriii
    Can anyone help me with creating this code in Java? PLEASE! Thanks in advance!

    Ask the user for the number of milliseconds, validate that it's not negative, and
    display the result, then ask if the user wants to convert another number
    (you may use a confirmation dialog, or you may allow input of 1 for yes
    and 2 for no). Keep converting milliseconds until the user chooses no.

    Example: (5500) should return 0:00:05 and convertMillis(1 00000) should return 0:01:40.

    except your result MUST be formatted so that minutes and seconds are always two digits

    Comment

    • BSCode266
      New Member
      • Jan 2007
      • 38

      #3
      Like hirak said we dont support full codes, you have to try and we will try to direct you in the right way.

      Also this sounds like an assignment to me.

      BSCode266

      Comment

      • RedSon
        Recognized Expert Expert
        • Jan 2007
        • 4980

        #4
        Using a good, clear thread title is important. The reasons for this are:

        * We want this site to grow, many of our new members find the site using a search engine, by using a good thread title you will help us grow the site by helping us get better search engine rankings.
        * Using a good title will benefit you too because other members of the forum will be less likely to skip over your thread and it allows the experts to quickly scan through the forum for questions they know the answer to.
        * If the threads are well titled it allows other users to easily see if there have been any threads that could be relevant to their own current problem.
        * It is in everybody's best interests to post properly titled threads as the more time the moderators have to spend on managing titles the less time they have available to give answers to the questions posed.

        Comment

        • Kuriii
          New Member
          • Apr 2007
          • 3

          #5
          Sorry guys.

          This is what I have so far. I can't figure out how the input can be converted.

          Thanks for your help in advance!

          Code:
          import javax.swing.JOptionPane;
          	public class extraCredit {
          
          	public static void main(String[] args) {
          	
          
          		
          	int choice;	
          	do {
                choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Do you want to enter the milliseconds now?\n   1. Yes\n     2.  No"));
          
                switch (choice) {
               	 case 1:
          		
          			int milli;
          		do {
          		milli = Integer.parseInt (JOptionPane.showInputDialog("Enter the number of milliseconds (Must be positive"));	
          			} 
          		while (milli < 0);
          		
                break;
          
          							}
          			}
          	while (choice != 2);
          
          	
          	
          		}
          }
          Last edited by RedSon; Apr 10 '07, 08:22 PM. Reason: Please use CODE tags!!!

          Comment

          • hirak1984
            Contributor
            • Jan 2007
            • 316

            #6
            Well you need not be sorry for whatever...
            By the way are you facing problem in converting the string input into integer(the Integer.parseIn t() stuff) or converting the input into millisecond?
            please make this clear and preferrably post the errors you are getting.
            Originally posted by Kuriii
            Sorry guys.

            This is what I have so far. I can't figure out how the input can be converted.

            Thanks for your help in advance!

            Code:
            import javax.swing.JOptionPane;
            	public class extraCredit {
            
            	public static void main(String[] args) {
            	
            
            		
            	int choice;	
            	do {
                  choice = Integer.parseInt(JOptionPane.showInputDialog(null, "Do you want to enter the milliseconds now?\n   1. Yes\n     2.  No"));
            
                  switch (choice) {
                 	 case 1:
            		
            			int milli;
            		do {
            		milli = Integer.parseInt (JOptionPane.showInputDialog("Enter the number of milliseconds (Must be positive"));	
            			} 
            		while (milli < 0);
            		
                  break;
            
            							}
            			}
            	while (choice != 2);
            
            	
            	
            		}
            }

            Comment

            • Kuriii
              New Member
              • Apr 2007
              • 3

              #7
              Hey

              Thanks for your help. I figured it out. I needed help with the conversion from seconds to milliseconds so I just created a formula. 1 second to 1000 milli seconds. It was pretty simple after I figured it out. Thanks for your help though:)

              Comment

              Working...