-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bb22f87
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
|
||
public class NinjaWarrior { | ||
|
||
//declare all private variables (add one for each stat) | ||
private int str; | ||
|
||
/** | ||
* this "constructs" an instance of our NinjaWarrior object | ||
* we pass it a variable as an "argument" for each "stat" that our NinjaWarrior has | ||
* so far, he only has one stat (strength) and I have chosen "int s" as the argument to represent that stat | ||
* between the brackets, we set each private variable (str) equal to its corresponding argument (s) | ||
*/ | ||
NinjaWarrior(int s) | ||
{ | ||
str = s; | ||
} | ||
|
||
/** | ||
* this is an example of a "set method" | ||
* set methods allow us to UPDATE the value of a stat | ||
*/ | ||
public void setStr(int s) | ||
{ | ||
str = s; | ||
} | ||
|
||
/** | ||
* this is an example of a "get method" | ||
* get methods allow us to access the value for a stat, which is helpful for when we want to print that stat | ||
*/ | ||
public int getStr() | ||
{ | ||
return str; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
public class main { | ||
|
||
/** | ||
* @param args | ||
*/ | ||
public static void main(String[] args) { | ||
|
||
//creates a NinjaWarrior object named player | ||
NinjaWarrior player = new NinjaWarrior(10); | ||
|
||
//we can run any of our methods on player using "player.methodNameHere | ||
System.out.println("Starting strength is "+player.getStr()); | ||
player.setStr(14); //updates the strength to 14 | ||
System.out.println("Strength is now "+player.getStr()); | ||
|
||
|
||
|
||
} | ||
|
||
} |