Skip to content

Commit f8b8f39

Browse files
authored
Merge branch 'code-differently:main' into main
2 parents d11b3b9 + 230265f commit f8b8f39

File tree

170 files changed

+21730
-38
lines changed

Some content is hidden

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

170 files changed

+21730
-38
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.codedifferently.lesson16.boxer;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.Random;
6+
7+
public class Boxer {
8+
public enum BoxerStyle {
9+
SWITCHHITTER,
10+
BOXERPUNCHER,
11+
SOUTHPAW,
12+
INFIGHTER,
13+
SLUGGER,
14+
OUTFIGHTER,
15+
ORTHODOX;
16+
}
17+
18+
public class BoxerIsRetiredException extends Exception {
19+
public BoxerIsRetiredException(String message) {
20+
super(message);
21+
}
22+
}
23+
24+
public class BoxerHasNoFightsException extends Exception {
25+
public BoxerHasNoFightsException(String message) {
26+
super(message);
27+
}
28+
}
29+
30+
private String name;
31+
private HashMap<String, Character> fights;
32+
private int power;
33+
private int health;
34+
private BoxerStyle skillSet;
35+
private boolean ableToFight;
36+
private BoxerStyle[] style = BoxerStyle.values();
37+
private static Random rand = new Random();
38+
39+
public Boxer(String name, int power, int health) {
40+
this.name = name;
41+
this.power = power;
42+
this.health = health;
43+
this.ableToFight = true;
44+
this.skillSet = BoxerStyle.ORTHODOX;
45+
fights = new HashMap<>();
46+
}
47+
48+
public String getName() {
49+
return name;
50+
}
51+
52+
public boolean getAbleToFight() {
53+
return ableToFight;
54+
}
55+
56+
public void workout(int additional) {
57+
power += additional;
58+
}
59+
60+
public int getPower() {
61+
return power;
62+
}
63+
64+
public int getHealth() {
65+
return health;
66+
}
67+
68+
public void rest() {
69+
health += 1;
70+
}
71+
72+
public void rollSkillSet() {
73+
int randomIndex = rand.nextInt(style.length);
74+
BoxerStyle newStyle = style[randomIndex];
75+
skillSet = newStyle;
76+
System.out.println("Random style: " + skillSet);
77+
}
78+
79+
public void addFights(String name, char d) throws BoxerIsRetiredException {
80+
if (ableToFight == false) {
81+
throw new BoxerIsRetiredException("Boxer is retired");
82+
}
83+
fights.put(name, d);
84+
}
85+
86+
public void retire() throws BoxerIsRetiredException {
87+
checkRetirementStatus();
88+
ableToFight = false;
89+
}
90+
91+
private void checkRetirementStatus() throws BoxerIsRetiredException {
92+
if (ableToFight == false) {
93+
throw new BoxerIsRetiredException("Boxer is already retired");
94+
}
95+
}
96+
97+
private void checkBoxerHasntFoughtAnyone() throws BoxerHasNoFightsException {
98+
if (fights.isEmpty()) {
99+
throw new BoxerHasNoFightsException("Boxer hasnt fought anyone");
100+
}
101+
}
102+
103+
public String getFights() throws BoxerHasNoFightsException {
104+
checkBoxerHasntFoughtAnyone();
105+
String fightsHad = "";
106+
for (Map.Entry<String, Character> entry : fights.entrySet()) {
107+
String key = entry.getKey();
108+
char value = entry.getValue();
109+
fightsHad += "fought: " + key + " " + value + ".";
110+
}
111+
return fightsHad;
112+
}
113+
114+
public void bout(Boxer boxer) throws BoxerIsRetiredException {
115+
if (ableToFight == false) {
116+
throw new BoxerIsRetiredException("Boxer is retired");
117+
}
118+
String boxerName = boxer.getName();
119+
if (power < boxer.getPower()) {
120+
ableToFight = false;
121+
fights.put(boxerName, 'L');
122+
} else if (power == boxer.getPower()) {
123+
fights.put(boxerName, 'D');
124+
} else {
125+
fights.put(boxerName, 'W');
126+
}
127+
}
128+
129+
public void setName(String name) {
130+
this.name = name;
131+
}
132+
133+
public void setHealth(int health) {
134+
this.health = health;
135+
}
136+
137+
public BoxerStyle getSkillSet() {
138+
return skillSet;
139+
}
140+
141+
public void setAbleToFight(boolean ableToFight) {
142+
this.ableToFight = ableToFight;
143+
}
144+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
package com.codedifferently.lesson16.boxer;
2+
3+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
7+
8+
import com.codedifferently.lesson16.boxer.Boxer.BoxerHasNoFightsException;
9+
import com.codedifferently.lesson16.boxer.Boxer.BoxerIsRetiredException;
10+
import org.junit.jupiter.api.BeforeEach;
11+
import org.junit.jupiter.api.Test;
12+
13+
public class BoxerTest {
14+
public enum testStyle {
15+
BASIC
16+
}
17+
18+
Boxer boxer;
19+
20+
@BeforeEach
21+
void setUp() {
22+
boxer = new Boxer("Joseph", 99, 99);
23+
}
24+
25+
@Test
26+
void testWorkout_addingTenPointsOfPower() {
27+
boxer.workout(10);
28+
assertEquals(109, boxer.getPower());
29+
}
30+
31+
@Test
32+
void testRest_restingToIncreaseHealth() {
33+
int previousHealth = boxer.getHealth();
34+
boxer.rest();
35+
assertNotEquals(boxer.getHealth(), previousHealth);
36+
}
37+
38+
@Test
39+
void testGetFightHistory_makingAFighterToHaveABout()
40+
throws BoxerHasNoFightsException, BoxerIsRetiredException {
41+
Boxer mike = new Boxer("mike", 1000, 1000);
42+
boxer.bout(mike);
43+
assertEquals("fought: " + mike.getName() + " L.", boxer.getFights());
44+
}
45+
46+
@Test
47+
void testIsAbleToFight_boxerIsNotRetiredOrInjured() {
48+
assertEquals(true, boxer.getAbleToFight());
49+
}
50+
51+
@Test
52+
void testIsAbleToFight_boxerIsNotAbleToFight() throws BoxerIsRetiredException {
53+
boxer.retire();
54+
assertEquals(false, boxer.getAbleToFight());
55+
}
56+
57+
@Test
58+
void testBout_makingNewBoxerToFightAnotherAndSeeTheResults() throws BoxerIsRetiredException {
59+
Boxer mike = new Boxer("Mike", 1000, 1000);
60+
boxer.bout(mike);
61+
assertEquals(false, boxer.getAbleToFight());
62+
}
63+
64+
@Test
65+
void testBout_makingNewBoxerToFightAndDraw()
66+
throws BoxerIsRetiredException, BoxerHasNoFightsException {
67+
Boxer ryan = new Boxer("Ryan Garcia", 99, 99);
68+
boxer.bout(ryan);
69+
assertEquals(boxer.getFights(), "fought: Ryan Garcia D.");
70+
}
71+
72+
@Test
73+
void testBout_makingNewBoxerToWinAgainstWithBoxer()
74+
throws BoxerIsRetiredException, BoxerHasNoFightsException {
75+
Boxer hitman = new Boxer("Thomas Hearns", 98, 98);
76+
boxer.bout(hitman);
77+
assertEquals(boxer.getFights(), "fought: " + hitman.getName() + " W.");
78+
}
79+
80+
@Test
81+
void testGetHealth() {
82+
assertEquals(boxer.getHealth(), 99);
83+
}
84+
85+
@Test
86+
void testRollSkillSet_testingBasicIsNotWhatIsRolled() {
87+
boxer.rollSkillSet();
88+
assertNotEquals(boxer.getSkillSet(), testStyle.BASIC);
89+
}
90+
91+
@Test
92+
void testAddFights() throws BoxerIsRetiredException, BoxerHasNoFightsException {
93+
boxer.addFights("Marvin Hagler", 'L');
94+
assertEquals(boxer.getFights(), "fought: Marvin Hagler L.");
95+
}
96+
97+
@Test
98+
void testAddFights_whenRetired() throws BoxerIsRetiredException {
99+
boxer.retire();
100+
assertThatThrownBy(
101+
() -> {
102+
boxer.addFights("lomachenko", 'W');
103+
})
104+
.isInstanceOf(BoxerIsRetiredException.class)
105+
.hasMessage("Boxer is retired");
106+
}
107+
108+
@Test
109+
void testRetire_whenRetired() throws BoxerIsRetiredException {
110+
boxer.retire();
111+
assertThatThrownBy(
112+
() -> {
113+
boxer.retire();
114+
})
115+
.isInstanceOf(BoxerIsRetiredException.class)
116+
.hasMessage("Boxer is already retired");
117+
}
118+
119+
@Test
120+
void testSetName() {
121+
boxer.setName("Pablo");
122+
assertEquals(boxer.getName(), "Pablo");
123+
}
124+
125+
@Test
126+
void testSetAbleToFight() {
127+
boxer.setAbleToFight(false);
128+
assertFalse(boxer.getAbleToFight());
129+
}
130+
131+
@Test
132+
void testSetHealth() {
133+
boxer.setHealth(2);
134+
assertEquals(boxer.getHealth(), 2);
135+
}
136+
137+
@Test
138+
void testBoxerIsRetiredException_retiringBoxerThenThrowingException()
139+
throws BoxerIsRetiredException {
140+
Boxer leaonard = new Boxer("Sugar ray", 200, 200);
141+
boxer.retire();
142+
assertThatThrownBy(
143+
() -> {
144+
boxer.bout(leaonard);
145+
})
146+
.isInstanceOf(BoxerIsRetiredException.class)
147+
.hasMessageContaining("Boxer is retired");
148+
}
149+
150+
@Test
151+
void testBoxerHasNoFightsException_gettingFightsWhenNoFightsHaveBeenHad() {
152+
assertThatThrownBy(
153+
() -> {
154+
boxer.getFights();
155+
})
156+
.isInstanceOf(BoxerHasNoFightsException.class)
157+
.hasMessageContaining("Boxer hasnt fought anyone");
158+
}
159+
}

lesson_22/David CD Replica/hero.jpg

329 KB
Loading

lesson_22/David CD Replica/index.html

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<html>
2+
<head>
3+
<title>Homepage</title>
4+
<meta name="viewport" content="width=device-width, initial-scale=1" />
5+
<link rel="stylesheet" id="redux-google-fonts-salient_redux-css" href="https://fonts.googleapis.com/css?family=Poppins%3A600%2C400%7CMontserrat%3A800%2C900%2C700&amp;ver=1597678827" type="text/css" media="all">
6+
<link rel='stylesheet' href='https://fonts.googleapis.com/css?family=Poppins%3A600%2C400%7CMontserrat%3A800%2C900%2C700&#038;ver=1597678827' type='text/css' media='all' />
7+
<link rel="stylesheet" type="text/css" href="style.css">
8+
</head>
9+
<body>
10+
<header class="header">
11+
<div class="header-logo">
12+
<a href="index.html">
13+
<img src="logo.png" alt="Code Differently Logo" />
14+
</a>
15+
</div>
16+
<ul class="header-top-menu">
17+
<li><a href="#">Home</a></li>
18+
<li><a href="#">About</a></li>
19+
<li><a href="#">Contact</a></li>
20+
</ul>
21+
<div class="header-cta">
22+
<a class="sign-up-button" href="#">Sign Up</a>
23+
</div>
24+
</header>
25+
<div class="main">
26+
<div class="content">
27+
<article>
28+
<section class="hero-section">
29+
<div class="hero-overlay"></div>
30+
<div class="hero-content">
31+
<h2 class="hero-title">Together we can move the needle of <em class="highlight">diversity in tech.</em></h2>
32+
<div class="hero-text"><span>Code Differently</span> provides hands on training and education through coding classes that gives participants the technical and cognitive skills they need to excel in technology-driven workplaces.</div>
33+
</div>
34+
</section>
35+
<section class="programs-section">
36+
<h2>Our <em class="highlight">Programs</em></h2>
37+
<ul class="programs">
38+
<li class="program">
39+
<h3>1000 Kids Coding</h3>
40+
<p>The Code Differently 1000 Kids Coding program was created to expose New Castle County students to computing and programming. The 1000 Kids Coding courses are designed for all experience levels, no experience required.</p>
41+
</li>
42+
<li class="program">
43+
<h3>Return Ready</h3>
44+
<p>The Code Differently Workforce Training Initiatives were created to help individuals underrepresented in tech reinvent their skills to align with the changing workforce market. If you are ready to start your tech journey, join our talent community today.</p>
45+
</li>
46+
<li class="program">
47+
<h3>Pipeline DevShops</h3>
48+
<p>Pipeline DevShop is a youth work-based learning program. Youth participants experience working in a real software development environment while sharpening their technology and soft skills.</p>
49+
</li>
50+
<li class="program">
51+
<h3>Platform Programs</h3>
52+
<p>Platform programs are designed for high school graduates, college students, career changers, or professionals looking to develop the technology job readiness skills for today’s workforce.</p>
53+
</li>
54+
</ul>
55+
</section>
56+
</article>
57+
</div>
58+
</div>
59+
<footer class="footer">
60+
&copy; 2024 Code Differently
61+
</footer>
62+
</body>
63+
</html>

lesson_22/David CD Replica/logo.png

29.2 KB
Loading

0 commit comments

Comments
 (0)