Kathryn shows you how to debug a Java program using print statements. In this example, you create and debug a coin-flipping program that uses the Random module, as well as an object-oriented programming style.
- [Instructor] In this video,…we are going to create a program…that simulates flipping a coin…and then debug that program using print statements.…To start off, here we have a coin class…and this coin class represents a coin.…We also have two final static int variables,…heads and tails,…that are represented by zero and one accordingly.…We also have this private int faceUp…and this keeps track of what the coin is faceUp on…and so if I flipped it and the faceUp is heads,…the faceUp would be zero.…
If I flipped it and the faceUp was tails,…the faceUp should be one tails.…Then we have our constructor on line 10…and basically this constructor allows us…to start with a faceUp either on heads or tails…or any other number we want that faceUp to start on.…Next, we have our flip method…and this is simulating flipping a coin…and so the way we do this…is we have a random number generator with the random class…and we basically get a random number…that's either zero or one…and make that the value of faceUp…with the nextInt method here and then our bound is two.…
- Downloading Java 9 and choosing an IDE
- Understanding Java basics: data types, strings, arrays, and more
- Controlling flow with functions and loops
- Working with inheritance and interfaces
- Learning lambda
Skill Level Beginner
1. Getting Started
2. Java Basics
3. Control Flow
4. Beyond the Basics
- 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.