Results 1 to 10 of 10

Thread: Help Debug

  1. #1
    Desmond is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default Help Debug

    Someone plz help me debug this simple code

    Java Code:
    import java.util.Scanner;
    
    class ReturnValue
    {
    	public static void main (String[] args)
    	{
    	long timePeriodMinutes	
            long timestamp1, timestamp2;
    
          System.out.println("Enter Two timestamps :");
          Scanner keyboard = new Scanner(System.in);
    
          timestamp1 = keyboard.nextLong();
          timestamp2 = keyboard.nextLong();
    
    
           System.out.println("Time in rounded minutes : "+timePeriodMinutes*(long            timestamp1, timestamp2));
    	}
    	  public*static*long*timePeriodMinutes*(long timestamp1, timestamp2)
    	{
    	 double*times;
             if*((timestamp1<0) || (timestamp2<0))
             times*=*-1;
           else
             times = (timestamp1-timestamp2)/(1000 *60);
             times = Math.abs(times);
             times = Math.ceil(times);
    
              return*times;
    	}
    }

  2. #2
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    6

    Default

    what do you mean with "help debug": debug with a walkthrough to understand what the code does, or debug with javac or debug in eclipse or what else?

  3. #3
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    I started to answer, and soon figured out it's either a joke or a homework assignment -- probably the latter. Do your own homework. If there's something you need help with, ask a specific question.

    -Gary-

  4. #4
    Desmond is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default

    Ok, the program is supossed to take to two numbers, timestamps, which are in milliseconds (1000th of a second), the program then finds the difference between the two time stamps (irregardless of the order, so it is bigger timestamp minus smaller timestamp).

    The program then converts the time difference to minutes, and it rounds up the time e.g if the minutes where 15.23mimutes, the answer would be 16 minutes. Also it returns an error code "-1" if one of the timestamp entered is negative.

    All this must be done within method defined by

    long timePeriodMinutes(long timestamp1, timestamp2)


    Hope that is clear enough

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Desmond View Post
    Hope that is clear enough
    Not quite. You never say what specifically you need help with, what's not working right, what bugs you've found. Please understand that this isn't a "dump my homework site". You must show a little initiative here.

  6. #6
    Desmond is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default

    Thank you Fuburable, you opinion is highly appreciated

  7. #7
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    On the off chance that there's actually some sincerity to your request, I'll just say that there is no debugging to be done. All you have to do is remove the complete stupidities from each line, and the program will work fine. If you can't recognize the stupidities, then go back to your text and study some more.

    And yes, I say stupidities and not errors, when I see things like this:
    Java Code:
    	  public*static*long*timePeriodMinutes*(long timestamp1, timestamp2)
    This is clearly an exercise for you to recognize and correct Java syntax. Just do it.

    -Gary-

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Desmond View Post
    Thank you Fuburable, you opinion is highly appreciated
    You're welcome, I'm sure ;), though you still might want to post what your errors are and give us the details. I'm guessing that some of the code above is from your instructor and that you are trying to use this code to create a functioning program but that it's not working, that you're having compile errors. So what you need to learn here is not just how to fix this program (although you need to know that), but how to better understand the compiler errors so you can fix it and similar future errors yourself -- it's the give a fish vs teach a man to fish scenario. So again, please give us as much detail on your problem itself and we can better help you. We're after the same goal after all -- improving your ability to code on your own and to learn something valuable.

    Much luck.
    Last edited by Fubarable; 03-18-2010 at 03:21 PM.

  9. #9
    Desmond is offline Member
    Join Date
    Mar 2010
    Posts
    17
    Rep Power
    0

    Default

    I think the crux is understanding declaring Methods calling them etc, otherwise I had the loosely structured program running, I am just still battling with understanding Methods. But in time all will be well and hopefully I won't be feeling so ridiculed.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Desmond View Post
    I think the crux is understanding declaring Methods calling them etc, otherwise I had the loosely structured program running, I am just still battling with understanding Methods. But in time all will be well and hopefully I won't be feeling so ridiculed.
    Please don't misunderstand us, as no one's ridiculing you for not being born knowing Java, as lord knows we're all ignorant when we start, but we do bristle when you post code or an assignment without asking an actual specific question. With time and practice both your questions and your understanding of Java will get better A site that has helped me to ask better questions here and may help you is this one: smart questions

    Again, much luck.
    Last edited by Fubarable; 03-18-2010 at 03:54 PM.

Similar Threads

  1. different behavior between debug and run
    By flaquitqm in forum Eclipse
    Replies: 1
    Last Post: 03-04-2010, 03:01 PM
  2. Help with debug
    By SwEeTAcTioN in forum New To Java
    Replies: 9
    Last Post: 11-22-2009, 04:39 AM
  3. error debug
    By stid in forum Eclipse
    Replies: 2
    Last Post: 10-16-2009, 07:44 PM
  4. How to debug javaScript?
    By kishan in forum Advanced Java
    Replies: 2
    Last Post: 07-24-2009, 09:16 AM
  5. Debug challenge: how do you debug a Java program?
    By CJSLMAN in forum New To Java
    Replies: 60
    Last Post: 07-04-2009, 10:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •