-
Notifications
You must be signed in to change notification settings - Fork 23
feat: adds David’s shinobi’s objects #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
VicenteVigueras
merged 3 commits into
code-differently:main
from
Dadenaike251:release/David.A-lesson16HW
May 16, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...s_app/src/main/java/com/codedifferently/lesson16/davidadenaike/RogueShinobiException.java
This file contains hidden or 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,7 @@ | ||
package com.codedifferently.lesson16.davidadenaike; | ||
|
||
public class RogueShinobiException extends Exception { | ||
public RogueShinobiException(String message) { | ||
super(message); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
...objects/objects_app/src/main/java/com/codedifferently/lesson16/davidadenaike/Shinobi.java
This file contains hidden or 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,96 @@ | ||
package com.codedifferently.lesson16.davidadenaike; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Shinobi { | ||
private String name; | ||
private Village village; | ||
private String rank; | ||
private int ryo; | ||
private char missionRank; | ||
private List<String> jutsus; | ||
|
||
public Shinobi(String name, Village village, String rank) throws RogueShinobiException { | ||
if ("rogue".equalsIgnoreCase(rank)) { | ||
throw new RogueShinobiException("You are a shame to all Shinobis!"); | ||
} | ||
|
||
this.name = name; | ||
this.village = village; | ||
this.rank = rank; | ||
this.ryo = 0; | ||
this.missionRank = 'D'; | ||
this.jutsus = new ArrayList<>(); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Village getVillage() { | ||
return village; | ||
} | ||
|
||
public String getRank() { | ||
return rank; | ||
} | ||
|
||
public int getRyo() { | ||
return ryo; | ||
} | ||
|
||
public void addRyo(int amount) { | ||
this.ryo += amount; | ||
} | ||
|
||
public char getMissionRank() { | ||
return missionRank; | ||
} | ||
|
||
public void setMissionRank(char missionRank) { | ||
this.missionRank = missionRank; | ||
} | ||
|
||
public void setRank(String rank) throws RogueShinobiException { | ||
if ("rogue".equalsIgnoreCase(rank)) { | ||
throw new RogueShinobiException("Cannot set rank to rogue!"); | ||
} | ||
this.rank = rank; | ||
} | ||
|
||
public String determineRank() { | ||
if (jutsus.size() >= 10 && missionRank == 'S') { | ||
return "Jōnin"; | ||
} else if (jutsus.size() >= 5 && (missionRank == 'A' || missionRank == 'B')) { | ||
return "Chūnin"; | ||
} else { | ||
return "Genin"; | ||
} | ||
} | ||
|
||
public List<String> getJutsus() { | ||
return new ArrayList<>(jutsus); | ||
} | ||
|
||
public void addJutsu(String jutsu) { | ||
jutsus.add(jutsu); | ||
} | ||
|
||
public boolean checkForPromotion() { | ||
String[] rankProgression = {"Genin", "Chūnin", "Jōnin"}; | ||
String currentDeterminedRank = determineRank(); | ||
|
||
for (int i = 0; i < rankProgression.length; i++) { | ||
if (rank.equals(rankProgression[i])) { | ||
// Check if there's a next rank and if the determined rank is higher | ||
if (i < rankProgression.length - 1 | ||
&& currentDeterminedRank.equals(rankProgression[i + 1])) { | ||
return true; | ||
} | ||
break; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...objects/objects_app/src/main/java/com/codedifferently/lesson16/davidadenaike/Village.java
This file contains hidden or 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,10 @@ | ||
package com.codedifferently.lesson16.davidadenaike; | ||
|
||
public enum Village { | ||
LEAF, | ||
SAND, | ||
MIST, | ||
CLOUD, | ||
STONE, | ||
SOUND | ||
} |
49 changes: 49 additions & 0 deletions
49
...cts/objects_app/src/test/java/com/codedifferently/lesson16/davidadenaike/ShinobiTest.java
This file contains hidden or 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,49 @@ | ||
package com.codedifferently.lesson16.davidadenaike; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ShinobiTest { | ||
|
||
@Test | ||
public void testCreateNormalShinobi() throws RogueShinobiException { | ||
Shinobi naruto = new Shinobi("Naruto", Village.LEAF, "Genin"); | ||
|
||
assertEquals("Naruto", naruto.getName()); | ||
assertEquals("Genin", naruto.getRank()); | ||
assertEquals('D', naruto.getMissionRank()); | ||
} | ||
|
||
@Test | ||
public void testPromotionEligibility() throws RogueShinobiException { | ||
Shinobi sasuke = new Shinobi("Sasuke", Village.LEAF, "Genin"); | ||
|
||
// Add requirements for Chunin | ||
sasuke.setMissionRank('A'); | ||
for (int i = 0; i < 5; i++) { | ||
sasuke.addJutsu("Jutsu" + i); | ||
} | ||
|
||
assertTrue(sasuke.checkForPromotion()); | ||
} | ||
|
||
@Test | ||
public void testAddJutsu() throws RogueShinobiException { | ||
Shinobi kakashi = new Shinobi("Kakashi", Village.LEAF, "Jōnin"); | ||
|
||
kakashi.addJutsu("Chidori"); | ||
assertTrue(kakashi.getJutsus().contains("Chidori")); | ||
assertEquals(1, kakashi.getJutsus().size()); | ||
} | ||
|
||
@Test | ||
public void testRyoManagement() throws RogueShinobiException { | ||
Shinobi sakura = new Shinobi("Sakura", Village.LEAF, "Chūnin"); | ||
|
||
assertEquals(0, sakura.getRyo()); | ||
sakura.addRyo(1000); | ||
assertEquals(1000, sakura.getRyo()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.