Skip to content

Commit 2fb00a4

Browse files
committed
feat:add oop principles HW (incomplete)
1 parent 7412c94 commit 2fb00a4

File tree

6 files changed

+177
-23
lines changed

6 files changed

+177
-23
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.onepiece;
2+
3+
public class HasNoDreamException extends Exception {
4+
public HasNoDreamException(String message) {
5+
super(message);
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.onepiece;
2+
3+
public class NotPirateException extends Exception {
4+
public NotPirateException(String message) {
5+
super(message);
6+
}
7+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.codedifferently.lesson16.onepiece;
2+
3+
import java.util.Random;
4+
5+
public class Pirate {
6+
public enum HakiType {
7+
Observation,
8+
Armament,
9+
Conquerors,
10+
Advanced_Observation,
11+
Advanced_Armament,
12+
Advanced_Conquerors,
13+
Will_of_D;
14+
}
15+
16+
private String name;
17+
private String crew;
18+
private long bounty;
19+
private boolean hasDream;
20+
private boolean isPirate;
21+
private HakiType powers;
22+
private final HakiType[] haki = HakiType.values();
23+
private static final Random cflip = new Random();
24+
25+
public Pirate(String name, String crew, long bounty) {
26+
this.name = name;
27+
this.crew = crew;
28+
this.bounty = bounty;
29+
this.hasDream = true;
30+
this.isPirate = true;
31+
this.powers = HakiType.Will_of_D;
32+
}
33+
34+
// Getters and setters
35+
public String getName() {
36+
return name;
37+
}
38+
39+
public String getCrew() {
40+
return crew;
41+
}
42+
43+
public long getBounty() {
44+
return bounty;
45+
}
46+
47+
public boolean getHasDream() {
48+
return hasDream;
49+
}
50+
51+
public boolean getIsPirate() {
52+
return isPirate;
53+
}
54+
55+
public void rollPowers() {
56+
int randomIndex = cflip.nextInt(haki.length);
57+
HakiType newHaki = haki[randomIndex];
58+
powers = newHaki;
59+
System.out.println("Random Haki: " + powers);
60+
}
61+
62+
public void setName(String name) {
63+
this.name = name;
64+
}
65+
66+
public void setCrew(String crew) {
67+
this.crew = crew;
68+
}
69+
70+
public void setBounty(Long bounty) {
71+
this.bounty = bounty;
72+
}
73+
74+
public void setHasDream(boolean hasDream) {
75+
this.hasDream = hasDream;
76+
}
77+
78+
public void setIsPirate(boolean isPirate) {
79+
this.isPirate = isPirate;
80+
}
81+
}

lesson_16/objects/objects_app/src/main/onepiece/DevilFruits.java

Lines changed: 0 additions & 11 deletions
This file was deleted.

lesson_16/objects/objects_app/src/main/onepiece/Haki.java

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.codedifferently.lesson16.onepiece;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class PirateTest {
8+
9+
Pirate pirate;
10+
11+
@BeforeEach
12+
void setUp() {
13+
pirate = new Pirate(2, "Zoro", "Swordsman", 900000);
14+
}
15+
16+
@Test
17+
void testGetId() {
18+
int actual = pirate.getId();
19+
20+
assertThat(actual).isEqualTo(2);
21+
}
22+
23+
@Test
24+
void testSetId() {
25+
pirate.setId(3);
26+
int actual = pirate.getId();
27+
28+
assertThat(actual).isEqualTo(3);
29+
}
30+
31+
@Test
32+
void testGetName() {
33+
String actual = pirate.getName();
34+
35+
assertThat(actual).isEqualTo("Zoro");
36+
}
37+
38+
@Test
39+
void testSetName() {
40+
pirate.setName("Sanji");
41+
String actual = pirate.getName();
42+
43+
assertThat(actual).isEqualTo("Sanji");
44+
}
45+
46+
@Test
47+
void testGetDepartment() {
48+
String actual = pirate.getDepartment();
49+
50+
assertThat(actual).isEqualTo("Swordsman");
51+
}
52+
53+
@Test
54+
void testSetDepartment() {
55+
pirate.setDepartment("Cook");
56+
String actual = pirate.getDepartment();
57+
58+
assertThat(actual).isEqualTo("Cook");
59+
}
60+
61+
@Test
62+
void testGetSalary() {
63+
double actual = pirate.getSalary();
64+
65+
assertThat(actual).isEqualTo(900000);
66+
}
67+
68+
@Test
69+
void testSetSalary() {
70+
pirate.setSalary(850000);
71+
double actual = pirate.getSalary();
72+
73+
assertThat(actual).isEqualTo(850000);
74+
}
75+
76+
@Test
77+
void testGetDetails() {
78+
String actual = pirate.getDetails();
79+
80+
assertThat(actual).isEqualTo("2 Zoro Swordsman 900000.0");
81+
}
82+
}

0 commit comments

Comments
 (0)