diff --git a/NinjaWarrior.java b/NinjaWarrior.java new file mode 100644 index 0000000..8ac1773 --- /dev/null +++ b/NinjaWarrior.java @@ -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; + } +} diff --git a/main.java b/main.java new file mode 100644 index 0000000..76aab33 --- /dev/null +++ b/main.java @@ -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()); + + + + } + +}