Skip to content

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
Merged
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
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);
}
}
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;
}
}
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
}
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());
}
}