In this video, Doug Winnie demonstrates how you can customize a function by passing in a value using a function parameter. Function parameters are giving a unique variable name that is used during the life of the function, and then can be used throughout the function code.
- [Narrator] When we have a function or method,…we can accept values to help define how it works.…We have one in our code here that we can customize,…by setting in a value inside to change how it works.…There are two changes I want to make.…The first is to change how we display…the score in the console.…Right now, we have it only happening…when we change the score.…As we have learned from functions,…we can group commonly used code using a function name.…Displaying the score is a common action.…
It doesn't make sense to have it just…happen in one place, so let's fix that.…We need to create a new method that will display the score.…Let's create a display score function…at the bottom of our code.…public static_void displayScore…We can then move the System.out statement from the check…score function, and put it in the display score function.…
Now we can call that in more than one place.…We can call a display score from the main constructor,…and the changed score method.…We can see how the score changes throughout the game.…
- The history of Java
- Setting up your development environment
- Working with values and variables
- Using methods and functions
- Capturing user input
- Creating conditional tests
- Using loops
- Creating and changing arrays
- Object-oriented programming in Java
- Defining permissions
- Extending classes
Skill Level Beginner
Computer Science Principles: The Internetwith Doug Winnie59m 30s Beginner
Java Essential Training for Studentswith Peggy Fisher3h 6m Intermediate
1. Intro to Java
2. Define Actions Using Code
3. Repeat Actions and Test for Conditions
4. Object-Oriented Programming Basics
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.