From ggc
|
01 packagepackage is used to name the directory or folder a class is in Hemendra.lights;
02
03 importimport means to make the classes and/or packages available in this program java.util.*;
04 importimport means to make the classes and/or packages available in this program wiki.Wiki;
05 /**
06 * All about my application here.
07 * @authorthis is the Javadoc tag for documenting who created the source code Hemendra Pullay
08 */
09 publicpublic is used to indicate unrestricted access (any other class can have access) classclass is a group of fields and methods used for making objects TextInterface
10 {open braces start code blocks and must be matched with a close brace
11 publicpublic is used to indicate unrestricted access (any other class can have access) staticstatic means that an instance is not required for access (class level access) voidvoid means the method does not return a value mainThe main method is the place where applications begin executing.(String[brackets are typically used to declare, initialize and index (indicate which element of) arrays]brackets are typically used to declare, initialize and index (indicate which element of) arrays args)
12 {open braces start code blocks and must be matched with a close brace
13 LightsOutModel model;
14 model=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor LightsOutModel();
15 whilewhile is a looping structure for executing code repeatedly(model.won()==this is the comparison operator which evaluates to true if both sides are the samefalsefalse is a value for the boolean type and means not true)
16 {open braces start code blocks and must be matched with a close brace
17 Wiki.out.println("Board:");
18 Wiki.out.println(model);
19 Wiki.out.println("What row would you like to play (0-4)?");
20 Scanner scanner=this assignment operator makes the left side equal to the right sidenewnew is used to create objects by calling the constructor Scanner(Wiki.in);
21 String number=this assignment operator makes the left side equal to the right sidescanner.next();
22 intint is the type for whole numbers and it is short for integer row=this assignment operator makes the left side equal to the right side-1;
23 trytry is for executing a code block that may experience exceptions (errors)
24 {open braces start code blocks and must be matched with a close brace
25 row=this assignment operator makes the left side equal to the right sideInteger.parseInt(number);
26 }close braces end code blocks and must match an earlier open brace
27 catchcatch means to handle an exception that may occur(NumberFormatException nfe)
28 {open braces start code blocks and must be matched with a close brace
29 Wiki.out.println("Not a number: "+adds two numbers together or concatenates Strings togethernumber);
30 }close braces end code blocks and must match an earlier open brace
31 Wiki.out.println("What column would you like to play (0-4)?");
32 number=this assignment operator makes the left side equal to the right sidescanner.next();
33 intint is the type for whole numbers and it is short for integer column=this assignment operator makes the left side equal to the right sideInteger.parseInt(number);
34 ifif executes the next statement only if the condition in parenthesis evaluates to true(row>=this evaluates to true if the left side is not less than the right side0 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) row <=this evaluates to true if the left side is not more than the right side4 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) column>=this evaluates to true if the left side is not less than the right side0 &this performs a bit-wise and (not the same as boolean and which is &&)&this performs a bit-wise and (not the same as boolean and which is &&) column<=this evaluates to true if the left side is not more than the right side4)
35 {open braces start code blocks and must be matched with a close brace
36 model.play(row, column);
37 }close braces end code blocks and must match an earlier open brace
38 elseelse is what happens when the if condition is false
39 {open braces start code blocks and must be matched with a close brace
40 ifif executes the next statement only if the condition in parenthesis evaluates to true(row<0)
41 {open braces start code blocks and must be matched with a close brace
42 Wiki.out.println("Row must be 0 to 4 inclusive (not negative).");
43 }close braces end code blocks and must match an earlier open brace
44 ifif executes the next statement only if the condition in parenthesis evaluates to true(column<0)
45 {open braces start code blocks and must be matched with a close brace
46 Wiki.out.println("Column must be 0 to 4 inclusive (not negative).");
47 }close braces end code blocks and must match an earlier open brace
48 ifif executes the next statement only if the condition in parenthesis evaluates to true(row>4)
49 {open braces start code blocks and must be matched with a close brace
50 Wiki.out.println("Row must be 0 to 4 inclusive (no larger than 4).");
51 }close braces end code blocks and must match an earlier open brace
52 ifif executes the next statement only if the condition in parenthesis evaluates to true(column>4)
53 {open braces start code blocks and must be matched with a close brace
54 Wiki.out.println("Column must be 0 to 4 inclusive (no larger than 4).");
55 }close braces end code blocks and must match an earlier open brace
56 }close braces end code blocks and must match an earlier open brace
57 }close braces end code blocks and must match an earlier open brace
58 Wiki.out.println("Congratulations, you won!");
59 }close braces end code blocks and must match an earlier open brace
60 }close braces end code blocks and must match an earlier open brace
|
Download/View Hemendra/lights/TextInterface.java