diff --git a/Pokemon/Answers/Geodude.java b/Pokemon/Answers/Geodude.java deleted file mode 100644 index 5102c22..0000000 --- a/Pokemon/Answers/Geodude.java +++ /dev/null @@ -1,21 +0,0 @@ -package JavaTraining2024.Pokemon.Answers; - -public class Geodude extends Pokemon { - - // default constructor, setting to 20 health and naming the pokemon "Geodude" - public Geodude() { - super(18, Geodude.class.getSimpleName()); // Fancy way of getting the name of the class - } - - // non-default constructor, allowing the user to specify Geodude's health and name - public Geodude(int health, String name) { - super(health, name); - } - - // Attack method for damaging an opposing pokemon - @Override - public void attack(Pokemon opposingPokemon) { - opposingPokemon.takeDamage(2); // I have decided that geodude's atack should do 2 damage - } - -} diff --git a/Pokemon/Answers/Jigglypuff.java b/Pokemon/Answers/Jigglypuff.java deleted file mode 100644 index d4be853..0000000 --- a/Pokemon/Answers/Jigglypuff.java +++ /dev/null @@ -1,21 +0,0 @@ -package JavaTraining2024.Pokemon.Answers; - -public class Jigglypuff extends Pokemon { - - // default constructor, setting to 15 health and naming the pokemon "Jigglypuff" - public Jigglypuff() { - super(15, "Jigglypuff"); - } - - // non-default constructor, allowing the user to specify Geodude's health and name - public Jigglypuff(int health, String name) { - super(health, name); - } - - // Attack method for damaging an opposing pokemon - @Override - public void attack(Pokemon opposingPokemon) { - opposingPokemon.takeDamage(3); // I have decided that jigglypuff's atack should do three damage - } - -} diff --git a/Pokemon/Answers/Main.java b/Pokemon/Answers/Main.java deleted file mode 100644 index 03928bc..0000000 --- a/Pokemon/Answers/Main.java +++ /dev/null @@ -1,35 +0,0 @@ -package JavaTraining2024.Pokemon.Answers; - -public class Main { - public static void main(String[] args) { - // Round 1 - Pokemon geodude = new Geodude(); - Pokemon jigglypuff = new Jigglypuff(); - - while (!geodude.getIsFainted() && !jigglypuff.getIsFainted()) { - geodude.attack(jigglypuff); - jigglypuff.attack(geodude); - } - - if (geodude.getIsFainted()) { - System.out.println("The winner is " + jigglypuff.getName()); - } else { - System.out.println("The winner is " + geodude.getName()); - } - - // Round 2 - Pokemon toughGuy = new Geodude(25, "Tough Guy"); - Pokemon littleBuddy = new Jigglypuff(12, "Little Buddy"); - - while (!toughGuy.getIsFainted() && !littleBuddy.getIsFainted()) { - toughGuy.attack(littleBuddy); - littleBuddy.attack(toughGuy); - } - - if (toughGuy.getIsFainted()) { - System.out.println("The winner is " + littleBuddy.getName()); - } else { - System.out.println("The winner is " + toughGuy.getName()); - } - } -} diff --git a/Pokemon/Answers/Pokemon.java b/Pokemon/Answers/Pokemon.java deleted file mode 100644 index 465c743..0000000 --- a/Pokemon/Answers/Pokemon.java +++ /dev/null @@ -1,29 +0,0 @@ -package JavaTraining2024.Pokemon.Answers; - -public abstract class Pokemon { - - private int health; - private String name; - - public Pokemon(int health, String name) { - this.health = health; - this.name = name; - } - - public void takeDamage(int damage) { - health -= damage; - } - - public abstract void attack(Pokemon opposingPokemon); - - public boolean getIsFainted() { - return health <= 0; - } - - public String getName(){ - return name; - } - public int getHealth(){ - return health; - } -} diff --git a/Pokemon/README.md b/Pokemon/README.md deleted file mode 100644 index 63bef29..0000000 --- a/Pokemon/README.md +++ /dev/null @@ -1,77 +0,0 @@ -# Let's Make Pokemon! - -## Rules -1. All classes must be in their own file (Packages) - -2. Mustuse public and private appropriately in all instance variables and methods (Encapsulation!) - -3. Must have comments above each method breifly explaining what it is intended to do - -4. Must have an abstract class “Pokemon” that all individual pokemon inherit from (Abstraction!) - - a. Must have an instance variable for health - - b. Must have an instance variable for name - - c. Must have a non-default constructor taking in parameters for initial health and name values and settingthe instance variables to those values - - d. Must have a defined (regular) method “take damage” that intakes an integer parameter and subtracts that value from health - - e. Must have abstract method “attack” that intakes a parameter of a Pokemon object (Abstraction!) - - f. Must have a getter “getIsFainted” that returns true or false for if the pokemon is dead (health <=0) - - g. Must have a getter "getName" that returns the name of the pokemon - -5. Must have a child class for individual pokemon (i.e. public class Jigglypuff) that extends (inherits from) Pokemon. Must make 1, it'd be better practice to make 2 - - a. Must overload (@override) the "attack" method (method polymorphism!). Call the "take damage" method of that pokemon inside of this method, passing in however much damge the attack is meant to do (subtype polymorphism!). If you want other effect to happen, put them here too! - - b. Must have a default constructor setting the "health" and "name" variables to reasonable default values (i.e. 14, "Jigglypuff") - - c. Must have a non-default constructor that sets "health" and "name" to values given in the parameters (method polymorphism!) - -6. Within a main method, make default objects of your pokemon and have them fight! - - a. In a while loop that continues until one or both pokemon have fainted, have them take turns attacking each other, passing the object of the defender into the attack method of the attacker - - b. Print out the name of your winner! - -7. Repeat 7, but with non-default objects of your pokemon (different health, different names) - - -## When you Finish - -1. Make sure you commit changes to github - -2. Make sure you push your changes (send them to the cloud) - -3. Make a Pull Request on your own github repo, see slides for how. In it, have your description/comment for it include the following: - - a. Explain why Pokemon should be an abstract class - - b. Explain why inheriting from Pokemon is useful - - c. Explain an example of method polymorphism in your code - - d. Explain an example of subtype polymorphism in your code - - e. Explain why you made one of your methods public - - f. Explain why you made one of your instance variables private - -Your explanations should have a bit of detail relating to specific parts of your code, not just citing things I've said or are written in these instructions - -3. Send a link to your github pull request to @Noah over discord. - -If you get it to me before Saturday, I will for sure review it before the end of the weekend. If you get it to me before Tuesday, I will review it before the next weekend - - -## Optional Further Practice -- Include Types (water, fire, grass) with strengths and weaknesses -- Include multiple different attacks on each pokemon -- Include levels that assign health values and change the damage dealt in the attack method -- Make "status conditions" (sleep, paralysis, poison) that have a percent chance to activate after an attack (import java.util.Random;, google how to use it to get random values) -- Give attacks a chance to miss - - diff --git a/README.md b/README.md index 7a145b6..6004465 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,37 @@ -# Java Training Exercises -🖊️ Exercises for our software training! +a. Explain why Pokemon should be an abstract class +Abstract classes cannot be instantiated, so there cannot be a Pokemon object. This makes sense because Pokemon itself is too general since there needs to be a specific type of Pokemon as an object. -## How to Use this Repository -
Click "Use this template" to create a fork-
- SELECT "Include all branches"-
-
-
-
-
-
- Change the base repository to-YOUR FORKnotTeam-Optix-3749: Java-Training
SHOULD NOT look like this-
- SHOULD look like this-
-
-
-
-