Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions Pokemon/Answers/Geodude.java

This file was deleted.

21 changes: 0 additions & 21 deletions Pokemon/Answers/Jigglypuff.java

This file was deleted.

35 changes: 0 additions & 35 deletions Pokemon/Answers/Main.java

This file was deleted.

29 changes: 0 additions & 29 deletions Pokemon/Answers/Pokemon.java

This file was deleted.

77 changes: 0 additions & 77 deletions Pokemon/README.md

This file was deleted.

97 changes: 36 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
<ol>
<li>
<details>
<summary> Complete activites in your own fork! 🍴</summary>
<hr>
<blockquote>Click "Use this template" to create a fork</blockquote>
<img src="https://cdn.discordapp.com/attachments/746794375203389572/1023586999740928000/unknown.png" >
<hr>
<blockquote>SELECT "Include all branches"</blockquote>
<img src="https://media.discordapp.net/attachments/746794375203389572/1023588065815560212/unknown.png" >
<hr>
</details>
</li>

<li>
<details>
<summary> Switch branches to see execersizes pertaining to each class 🌲</summary>
<hr>
<img src="https://media.discordapp.net/attachments/746794375203389572/1023585545999351949/unknown.png" >
<hr>
</details>
</li>

<li>
<details>
<summary> Find exercises in .md files from their respective folders & subtopics 📂</summary>
<hr>
<img src="https://media.discordapp.net/attachments/746794375203389572/1023593205943521320/unknown.png?width=750&height=670" >
<hr>
<img src="https://media.discordapp.net/attachments/746794375203389572/1023593376207093871/unknown.png" >
<hr>
</details>
</li>

<li>
<details>
<summary> When a whole day is complete, create a pull request to merge your branch to the main branch (This is what the leads will be looking for) 📫</summary>
<hr>
<img src="https://user-images.githubusercontent.com/69406769/190993256-68198a75-2c16-4302-9b79-017632603694.png" >
<hr>
<img src="https://user-images.githubusercontent.com/69406769/190993317-bdbc4466-1232-41a0-a77f-ae6ba1bc8e26.png" >
<hr>
<blockquote>Change the base repository to <code>YOUR FORK</code> not <code>Team-Optix-3749: Java-Training</code></blockquote>
<blockquote>SHOULD NOT look like this</blockquote>
<img src="https://media.discordapp.net/attachments/882455696199807007/1022321700261613608/unknown.png" >
<blockquote>SHOULD look like this</blockquote>
<img src="https://media.discordapp.net/attachments/882455696199807007/1022322140835491850/unknown.png">
<hr>
<img src="https://media.discordapp.net/attachments/882455696199807007/1022323086172893205/unknown.png" >
<hr>
<img src="https://media.discordapp.net/attachments/882455696199807007/1022323511152357486/unknown.png" >
<hr>
<img src="https://cdn.discordapp.com/attachments/882455696199807007/1022323636218118184/unknown.png" >
<hr>
</details>
</li>

</ol>
b. Explain why inheriting from Pokemon is useful
The Pokemon class contains general attributes that specific Pokemon classes can inherit from. This is useful because although different types of Pokemon are different, they all share common attributes that may become repetitive if the same code is rewritten for multiple classes. An example of how this is useful is how the attack method is overidden in the Jigglypuff and Pikachu classes.
``` java
@Override
void attack(Pokemon obj) {
obj.takeDamage(15);
}
```
c. Explain an example of method polymorphism in your code
The attack method in the Pokemon class is defined with no additional code. The method override for the attack method in the Pikachu class uses the takeDamage method to specify a specific amount of damage dealt thats unique to the Pikachu class.
```java
@Override
void attack(Pokemon obj) {
obj.takeDamage(25);
}
```
d. Explain an example of subtype polymorphism in your code
j and p are referenced to the Pokemon class but are instances of the Jigglypuff and Pikachu classes. This shows how Jigglypuff and Pikachu are subclasses of Pokemon.
```java
Pokemon j = new Jigglypuff(100, "Jigglypuff");
Pokemon p = new Pikachu(100, "Pikachu");
```
e. Explain why you made one of your methods public
I made getName() public because its a getter method so its purpose is for outside classes to access the value of the private variable name.
```java
public String getName() {
return name;
}
```
f. Explain why you made one of your instance variables private
I made the health variable private because the health should not be able to be modified from outside classes. It should only be used and changed in controlled ways, such as through methods in the class.
```java
private int health;
```
13 changes: 13 additions & 0 deletions Week4/Jigglypuff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Week4;

public class Jigglypuff extends Pokemon{
// have jigglypuff attack its opponent
@Override
void attack(Pokemon obj) {
obj.takeDamage(15);
}
//constructor
Jigglypuff (int health, String name) {
super(health, name);
}
}
21 changes: 21 additions & 0 deletions Week4/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package Week4;

public class Main {
public static void main(String[] args) {
// create jigglypuff and pikachu objects
Pokemon j = new Jigglypuff(100, "Jigglypuff");
Pokemon p = new Pikachu(100, "Pikachu");
// have the pokemons attack each other until one collapses
while(!j.getIsFainted() && !p.getIsFainted()) {
j.attack(p);
p.attack(j);
}
// printing the winner
if (j.getIsFainted()) {
System.out.println("Pikachu won!");

} else {
System.out.println("Jigglypuff won!");
}
}
}
13 changes: 13 additions & 0 deletions Week4/Pikachu.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Week4;

public class Pikachu extends Pokemon{
// have pikachu do damage to its opponent
@Override
void attack(Pokemon obj) {
obj.takeDamage(25);
}
// constructor
Pikachu (int health, String name) {
super(health, name);
}
}
30 changes: 30 additions & 0 deletions Week4/Pokemon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package Week4;

public abstract class Pokemon {
//private instance variables
private int health;
private String name;
// constructor
Pokemon (int health, String name) {
this.health = health;
this.name = name;
}
// subtract health when taken damage
public void takeDamage(int damage) {
health -= damage;
}
// attack method
abstract void attack(Pokemon obj);
// check if pokemon collapsed
public boolean getIsFainted() {
if (health <= 0) {
return true;
}
else {
return false;
}
}
public String getName() {
return name;
}
}