Advertisement
Guest User

Untitled

a guest
Sep 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. Ill explain this in bits over the first few lectures as quite a lot is going on, but yes it sounds like you've roughly got it - here is a brief version now that hopefully just says what you were thinking but sprinkled with some terminology.
  2. In the paralympics program.
  3. the statement
  4. inputString("Which paralympic sports do you like?");" line 20
  5. is a method call. A method is like a mini recipe for a bit of useful code - how to do something useful. Inputting a String is useful so Ive written a method I can use in any program I write so I dont have to write bespoke code to do it every time. The call is the command that tells the program (when executed) to jump to that methods definition (where its actual code is) do it THEN jump back and carry on - a bit like in a recipe where it might say
  6. ("Next cook the Turnip Broth (see page 47")) You jump to page 47 cook the Turnip following that recipe then jump back and carry on.
  7. A method call is just the name of the method followed by any information it needs to do its job.
  8. Now the inputString method needs to know what to print that tells the user what to do, so it needs to be passed that information. That information is called an argument and it needs to be stored somewhere. Data is stored in variables (a bit like storage boxes) so that string value "Which paralympic sports do you like?" that is passed (ie is in the (... ) of the call) is stored in the variable message owned by method inputString. The later instructions in inputString's definition and in particular the println statement can get at that passed information by referring to the variable name and so print it out as the message asking for the user to type something.
  9. So System.out.println(message); is actually a command this time to print "Which paralympic sports do you like?"
  10. If the main method also had a second call,
  11. inputString("Phew!");
  12. then it would do it again but this time the command
  13. System.out.println(message); would actually be actually a command this time to print "Phew!" as that would be what is stored in variable message that time.
  14. Anyone else reading who is a novice dont worry if you dont get this yet, but do have a look at that paralympic program and run in it and see if you can work out whats going on.
  15. Paul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement