YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Output From a Method - Solution

Get Embed Code
13 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. The first method is about
    getting the email account name.
  2. The method should return a string,
    which is the name of the account.
  3. So far, the method signature looks good.
  4. We have the access modifier, the return
    data type, and the method name, and
  5. no input params.
  6. You have a opening and
    closing brace as well.
  7. The first line of code looks correct.
  8. It returns a string in quotes,
    and then it has a semicolon.
  9. So, this is the return value.
  10. However, the problem comes on a second
    line when we see another return
  11. statement with another return value.
  12. We learned earlier that you can't have
    lines of code after the return statement
  13. because those will be considered
    unreachable by the computer.
  14. So in this case,
    this method has an error on line 8.
  15. Okay, so let's do Method 2 now.
  16. The second method is about adding
    $4 of tip onto the current bill.
  17. The current bill is an input parameter,
    and the data type is integer.
  18. The return value of the method should be
    the total price of the bill with that $4
  19. of tip included.
  20. So let's check the method
    signature first.
  21. We have a access modifier.
  22. We're missing our return data type,
    so that's weird.
  23. And then we have the method name and
    one input parameter.
  24. So the return data type is a red flag,
    but let's keep reading.
  25. Inside the method it says
    return bill +4 and semicolon.
  26. So this is the return value.
  27. Bill is a variable and we add four to
    it, so this evaluates to a single value.
  28. And then that is an integer
    which should get returned.
  29. So we're missing
    the word int right here.
  30. And this is on line 6.
  31. So in the table we say that Method
    2 has an error on line 6 and
  32. we're supposed to specify
    the return data type of int.
  33. Let's look at the third method.
  34. This method is about setting up
    the app for our current city.
  35. We don't have the code for
    the other app.
  36. But let's just look at the code for
    this one method.
  37. The method signature starts
    with private access modifier.
  38. And then it says nothing, which is weird
    because we haven't seen that before.
  39. And then the method
    name is called setup.
  40. There's no input parameters and
    we have an open and closing brace.
  41. Inside the method we see
    that there is a variable, it
  42. looks like a global variable city name
    and it's being set to the string London.
  43. Okay, well, from everything that I've
    observed there's basically no return
  44. data type specified in the comment here.
  45. It looks like we're trying to
    return nothing as the output, so
  46. remember that the Java keyword for
    returning nothing is the word void.
  47. So I think the error is on line
    4 here when we need to say void.
  48. Okay so I added that to the table.
  49. Now let's move on to Method 4.
  50. This method is about getting
    the number of students in a class.
  51. The return value is the number
    of students which is an integer.
  52. The method starts with
    an axis modifier of private.
  53. And then the return data type is
    an int so, so far it's looking good.
  54. The method name is getStudentClassSize
    and there's no input params.
  55. Inside the method,
    we have the return keyword and
  56. then it says 20 in quotations, but
  57. this is weird because this is a string
    and we want it to return an integer.
  58. So the error is on line 7, where we
    have to return 20 without quotations.
  59. And this is what your
    table should look like.