Java Help :@

Hi oL.

With regards to question 1, you are missing a return statement. The method should always return a String or a null, through all paths of execution. Should an error be thrown and caught by Catch, you're method doesn't return anything.

Code:
 catch(Exception e)
        {
            System.out.println("error");
            return null; //Returns Null.
        }

 catch(Exception e)
        {
            System.out.println("error");
            return ""; //Returns empty string.
        }
 
Some more feedback, sorry I'm not doing you're Uni work for you.

2 A) Where's the return statements? Why are you setting dob to 0.0 twice?

2 B) Again Return statements. You'll only ever move through the loop if you get a numberformatexception, is this correct?

Have you run this code at all? Or even compiled it?
 
numnutz, thanks for the feedback. It's ok, I don't expect you to do it for me. I've added some return statements, but not correctly I think :/

About the dob = 0.0 twice, well I'm not exactly sure, someone helped me on that part.

First post is edited.

I've tried to run it yes, but it won't compile yet.

Btw if you haven't noticed I'm not very good at progamming :p
 
the answer to Q1 is a lot simpler.. but difficult to explain, but I'll try..

You're being passed a calendar that has a specific date set on it. To be exact, it is a specific time. So ask the calendar for this time, then ask your formatter to format it. Cryptic.

Q2 is fine, could be improved, but nothing drastic about it.

Q3.. you need to take the characters from the string that are digits. I'll give a massive pointer here, in the direction of Character.isDigit()..
Code:
for (int i = 0; i < value.length(); i++) {
  if (Character.isDigit(value.charAt(i)) {
    // do something
  }
}
 
Last edited:
I wish people wouldn't edit/correct/remove their original post - it makes the thread pointless to anyone else that may want to read it/find it useful. :o
 
Back
Top Bottom