Skip to content

Commit 3570df5

Browse files
authored
Merge branch 'code-differently:main' into lesson_28
2 parents b093e25 + e9281a0 commit 3570df5

File tree

606 files changed

+110075
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

606 files changed

+110075
-131
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,7 @@ pip-log.txt
152152
.env*.local
153153

154154
# Custom
155-
!slides/dist/
155+
!slides/dist/
156+
157+
# Lecture notes
158+
lecture_notes

capstone/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ For your presentation, you will be given up to 20 minutes to feature your projec
107107
- [ ] Lastly, talk through technical challenges and features.
108108
3. You will be given 5 minutes for Q&A and take questions from the audience.
109109

110+
### Feedback
111+
112+
Please use [this link](https://forms.gle/f4UbB7fWir6Gx2iUA) to submit feedback on your teammates for grading.
113+
110114
### Academic Integrity
111115

112116
Please refer to the [Academic Integrity][academic-integrity-link] section of the syllabus regarding the use of third-party code and resources that you have used for your project. Give credit to where credit is due!
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.davidadenaike;
2+
3+
public class RogueShinobiException extends Exception {
4+
public RogueShinobiException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.codedifferently.lesson16.davidadenaike;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class Shinobi {
7+
private String name;
8+
private Village village;
9+
private String rank;
10+
private int ryo;
11+
private char missionRank;
12+
private List<String> jutsus;
13+
14+
public Shinobi(String name, Village village, String rank) throws RogueShinobiException {
15+
if ("rogue".equalsIgnoreCase(rank)) {
16+
throw new RogueShinobiException("You are a shame to all Shinobis!");
17+
}
18+
19+
this.name = name;
20+
this.village = village;
21+
this.rank = rank;
22+
this.ryo = 0;
23+
this.missionRank = 'D';
24+
this.jutsus = new ArrayList<>();
25+
}
26+
27+
public String getName() {
28+
return name;
29+
}
30+
31+
public Village getVillage() {
32+
return village;
33+
}
34+
35+
public String getRank() {
36+
return rank;
37+
}
38+
39+
public int getRyo() {
40+
return ryo;
41+
}
42+
43+
public void addRyo(int amount) {
44+
this.ryo += amount;
45+
}
46+
47+
public char getMissionRank() {
48+
return missionRank;
49+
}
50+
51+
public void setMissionRank(char missionRank) {
52+
this.missionRank = missionRank;
53+
}
54+
55+
public void setRank(String rank) throws RogueShinobiException {
56+
if ("rogue".equalsIgnoreCase(rank)) {
57+
throw new RogueShinobiException("Cannot set rank to rogue!");
58+
}
59+
this.rank = rank;
60+
}
61+
62+
public String determineRank() {
63+
if (jutsus.size() >= 10 && missionRank == 'S') {
64+
return "Jōnin";
65+
} else if (jutsus.size() >= 5 && (missionRank == 'A' || missionRank == 'B')) {
66+
return "Chūnin";
67+
} else {
68+
return "Genin";
69+
}
70+
}
71+
72+
public List<String> getJutsus() {
73+
return new ArrayList<>(jutsus);
74+
}
75+
76+
public void addJutsu(String jutsu) {
77+
jutsus.add(jutsu);
78+
}
79+
80+
public boolean checkForPromotion() {
81+
String[] rankProgression = {"Genin", "Chūnin", "Jōnin"};
82+
String currentDeterminedRank = determineRank();
83+
84+
for (int i = 0; i < rankProgression.length; i++) {
85+
if (rank.equals(rankProgression[i])) {
86+
// Check if there's a next rank and if the determined rank is higher
87+
if (i < rankProgression.length - 1
88+
&& currentDeterminedRank.equals(rankProgression[i + 1])) {
89+
return true;
90+
}
91+
break;
92+
}
93+
}
94+
return false;
95+
}
96+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.codedifferently.lesson16.davidadenaike;
2+
3+
public enum Village {
4+
LEAF,
5+
SAND,
6+
MIST,
7+
CLOUD,
8+
STONE,
9+
SOUND
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.nintendoswitch;
2+
3+
public class InvalidBatteryException extends Exception {
4+
public InvalidBatteryException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package com.codedifferently.lesson16.nintendoswitch;
2+
3+
import java.util.ArrayList;
4+
5+
public class nintendo {
6+
7+
public enum Model {
8+
STANDARD,
9+
LITE,
10+
OLED
11+
}
12+
13+
private String serialNumber;
14+
private Model model;
15+
private boolean isDocked;
16+
private double batteryLife; // This will be in hours.
17+
private ArrayList<String> installedGames;
18+
19+
/**
20+
* Constructs a Nintendo Switch object with the specified attributes.
21+
*
22+
* @param serialNumber serial number of the device
23+
* @param model the model type of the Nintendo Switch
24+
* @param isDocked indicates if the device is currently docked
25+
* @param batteryLife current battery life in hours
26+
* @param installedGames list of games currently installed on the device
27+
*/
28+
public nintendo(
29+
String serialNumber,
30+
Model model,
31+
boolean isDocked,
32+
double batteryLife,
33+
ArrayList<String> installedGames) {
34+
this.serialNumber = serialNumber;
35+
this.model = model;
36+
this.isDocked = isDocked;
37+
this.batteryLife = batteryLife;
38+
this.installedGames = installedGames;
39+
}
40+
41+
public class InvalidBatteryException extends Exception {
42+
public InvalidBatteryException(String message) {
43+
super(message);
44+
}
45+
}
46+
47+
/**
48+
* Checks the current battery status of the Nintendo Switch. If the battery life is negative, it
49+
* throws an InvalidBatteryException.
50+
*
51+
* @throws InvalidBatteryException if battery life is less than 0
52+
*/
53+
public void checkBatteryStatus() throws InvalidBatteryException {
54+
if (batteryLife < 0) {
55+
throw new InvalidBatteryException("Battery life cannot be negative.");
56+
}
57+
System.out.println("Battery life: " + batteryLife + " hours.");
58+
}
59+
60+
/**
61+
* Installs a game to the Nintendo Switch.
62+
*
63+
* @param game the name of the game to install
64+
*/
65+
public void installGame(String game) {
66+
installedGames.add(game);
67+
System.out.println(game + " has been added to your Nintendo Switch.");
68+
}
69+
70+
/** Displays all the games currently installed on the Nintendo Switch. */
71+
public void displayInstalledGames() {
72+
System.out.println("Installed games on the Nintendo Switch:");
73+
/** Using a normal for loop to iterate over installed games */
74+
for (int i = 0; i < installedGames.size(); i++) {
75+
System.out.println("- " + installedGames.get(i));
76+
}
77+
}
78+
79+
/* Getter methods */
80+
public String getSerialNumber() {
81+
return serialNumber;
82+
}
83+
84+
public Model getModel() {
85+
return model;
86+
}
87+
88+
public boolean isDocked() {
89+
return isDocked;
90+
}
91+
92+
public double getBatteryLife() {
93+
return batteryLife;
94+
}
95+
96+
public ArrayList<String> getInstalledGames() {
97+
return installedGames;
98+
}
99+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.codedifferently.lesson16.davidadenaike;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
public class ShinobiTest {
9+
10+
@Test
11+
public void testCreateNormalShinobi() throws RogueShinobiException {
12+
Shinobi naruto = new Shinobi("Naruto", Village.LEAF, "Genin");
13+
14+
assertEquals("Naruto", naruto.getName());
15+
assertEquals("Genin", naruto.getRank());
16+
assertEquals('D', naruto.getMissionRank());
17+
}
18+
19+
@Test
20+
public void testPromotionEligibility() throws RogueShinobiException {
21+
Shinobi sasuke = new Shinobi("Sasuke", Village.LEAF, "Genin");
22+
23+
// Add requirements for Chunin
24+
sasuke.setMissionRank('A');
25+
for (int i = 0; i < 5; i++) {
26+
sasuke.addJutsu("Jutsu" + i);
27+
}
28+
29+
assertTrue(sasuke.checkForPromotion());
30+
}
31+
32+
@Test
33+
public void testAddJutsu() throws RogueShinobiException {
34+
Shinobi kakashi = new Shinobi("Kakashi", Village.LEAF, "Jōnin");
35+
36+
kakashi.addJutsu("Chidori");
37+
assertTrue(kakashi.getJutsus().contains("Chidori"));
38+
assertEquals(1, kakashi.getJutsus().size());
39+
}
40+
41+
@Test
42+
public void testRyoManagement() throws RogueShinobiException {
43+
Shinobi sakura = new Shinobi("Sakura", Village.LEAF, "Chūnin");
44+
45+
assertEquals(0, sakura.getRyo());
46+
sakura.addRyo(1000);
47+
assertEquals(1000, sakura.getRyo());
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.codedifferently.lesson16.nintendoswitch;
2+
3+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import java.io.ByteArrayOutputStream;
9+
import java.io.PrintStream;
10+
import java.util.ArrayList;
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.Test;
13+
14+
public class nintendoswitchtest {
15+
16+
private nintendo ns;
17+
private ArrayList<String> games;
18+
19+
@BeforeEach
20+
void setUp() {
21+
games = new ArrayList<>();
22+
ns = new nintendo("SN001", nintendo.Model.STANDARD, true, 5.0, games);
23+
}
24+
25+
@Test
26+
void testInstallGame() {
27+
ns.installGame("Zelda");
28+
29+
assertTrue(games.contains("Zelda"), "Game should be installed");
30+
}
31+
32+
@Test
33+
void testCheckBatteryStatusValid() {
34+
assertDoesNotThrow(
35+
() -> ns.checkBatteryStatus(),
36+
"Battery check should not throw an exception for valid battery");
37+
}
38+
39+
@Test
40+
void testCheckBatteryStatusInvalid() {
41+
nintendo faultySwitch =
42+
new nintendo("SN002", nintendo.Model.LITE, false, -2.0, new ArrayList<>());
43+
44+
assertThrows(
45+
nintendo.InvalidBatteryException.class,
46+
faultySwitch::checkBatteryStatus,
47+
"Negative battery should throw InvalidBatteryException");
48+
}
49+
50+
@Test
51+
void testDisplayInstalledGames() {
52+
games.add("Mario Kart");
53+
games.add("Smash Bros");
54+
55+
ByteArrayOutputStream output = new ByteArrayOutputStream();
56+
System.setOut(new PrintStream(output));
57+
58+
ns.displayInstalledGames();
59+
60+
String printedOutput = output.toString();
61+
62+
assertTrue(printedOutput.contains("Mario Kart"));
63+
assertTrue(printedOutput.contains("Smash Bros"));
64+
65+
System.setOut(System.out);
66+
}
67+
68+
@Test
69+
void testInstallMultipleGames() {
70+
ns.installGame("Animal Crossing");
71+
ns.installGame("Splatoon");
72+
73+
assertEquals(2, games.size(), "Two games should be installed");
74+
assertTrue(games.contains("Animal Crossing"));
75+
assertTrue(games.contains("Splatoon"));
76+
}
77+
}

0 commit comments

Comments
 (0)