hello! newbie here

So I've come to realize that if I want to get many of my ideas going I need to learn programming.

Many years ago, I took Java, now I am back at it, but this time straight to a 200 level, where it is assumed I know the basics. I have about 2 weeks until things really start moving, so right now I am reading and experimenting about for about 6 or so hours a day. I've been reading a good text, and been fairly coherent thus far 200 pages in, except for now they have thrown an example down without explaining half the stuff.

I have some q's regarding this very simple example that uses 2 classes. Now, I like to analyze things waaay further than any book, so forgive me if I overkill the q's, but its also a bit of built up q's from previous pages. Hopefully there are some patient hackers around here

My questions start with a “//###”

I guess that’s enough qs for now, thanks for any takers. My main confusion lies in how the face = (int) (Math.random() * 2 can return (face == HEADS) ????Code://******************************************************************** // CountFlips.java Author: Lewis/Loftus // // Demonstrates the use of a programmer-defined class. //******************************************************************** public class CountFlips { //----------------------------------------------------------------- // Flips a coin multiple times and counts the number of heads // and tails that result. //### WHY do we need “(String[] args)”? rather than just ()? //----------------------------------------------------------------- public static void main (String[] args) { final int NUM_FLIPS = 1000; int heads = 0, tails = 0; Coin myCoin = new Coin(); // instantiate the Coin object for (int count=1; count <= NUM_FLIPS; count++) { myCoin.flip(); if (myCoin.isHeads()) heads++; else tails++; } System.out.println ("The number flips: " + NUM_FLIPS); System.out.println ("The number of heads: " + heads); System.out.println ("The number of tails: " + tails); } } ******************************************************************** // Coin.java Author: Lewis/Loftus // // Represents a coin with two sides that can be flipped. //******************************************************************** import java.util.Random; public class Coin { private final int HEADS = 0; private final int TAILS = 1; private int face; //----------------------------------------------------------------- // Sets up the coin by flipping it initially. // //----------------------------------------------------------------- public Coin () { flip(); } //----------------------------------------------------------------- // Flips the coin by randomly choosing a face value. // ###BUT why does it need to be void? // ###IS it public mainly because the above method is also public? // ###WHAT is with the *2 ?? and how does the function give a “HEADS or // TAILS kind of answer? //### why cant this method and the above flip() somehow be //combined into one method?? //----------------------------------------------------------------- public void flip () { face = (int) (Math.random() * 2); } //----------------------------------------------------------------- // Returns true if the current face of the coin is heads. //###really not seeing how face would equal // HEADS from above face calc. //----------------------------------------------------------------- public boolean isHeads () { return (face == HEADS); } //----------------------------------------------------------------- // Returns the current face of the coin as a string. // //----------------------------------------------------------------- public String toString() { String faceName; if (face == HEADS) faceName = "Heads"; else faceName = "Tails"; return faceName; } }

BTW: I did run this and it does work.