Skip to content

feat:add oop principles HW (incomplete) #518

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 3 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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.onepiece;

public class HasNoDreamException extends Exception {
public HasNoDreamException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedifferently.lesson16.onepiece;

public class NotPirateException extends Exception {
public NotPirateException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.codedifferently.lesson16.onepiece;

import java.util.Random;

public class Pirate {
public enum HakiType {
Observation,
Armament,
Conquerors,
Advanced_Observation,
Advanced_Armament,
Advanced_Conquerors,
Will_of_D;
}

private String name;
private String crew;
private long bounty;
private boolean hasDream;
private boolean isPirate;
private HakiType powers;
private final HakiType[] haki = HakiType.values();
private static final Random cflip = new Random();

public Pirate(String name, String crew, long bounty) {
this.name = name;
this.crew = crew;
this.bounty = bounty;
this.hasDream = true;
this.isPirate = true;
this.powers = HakiType.Will_of_D;
}

// Getters and setters
public String getName() {
return name;
}

public String getCrew() {
return crew;
}

public long getBounty() {
return bounty;
}

public boolean getHasDream() {
return hasDream;
}

public boolean getIsPirate() {
return isPirate;
}

public void rollPowers() {
int randomIndex = cflip.nextInt(haki.length);
HakiType newHaki = haki[randomIndex];
powers = newHaki;
System.out.println("Random Haki: " + powers);
}

public void setName(String name) {
this.name = name;
}

public void setCrew(String crew) {
this.crew = crew;
}

public void setBounty(Long bounty) {
this.bounty = bounty;
}

public void setHasDream(boolean hasDream) {
this.hasDream = hasDream;
}

public void setIsPirate(boolean isPirate) {
this.isPirate = isPirate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.codedifferently.lesson16.onepiece;

import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class PirateTest {

Pirate pirate;

@BeforeEach
void setUp() {
pirate = new Pirate(2, "Zoro", "Swordsman", 900000);
}

@Test
void testGetId() {
int actual = pirate.getId();

assertThat(actual).isEqualTo(2);
}

@Test
void testSetId() {
pirate.setId(3);
int actual = pirate.getId();

assertThat(actual).isEqualTo(3);
}

@Test
void testGetName() {
String actual = pirate.getName();

assertThat(actual).isEqualTo("Zoro");
}

@Test
void testSetName() {
pirate.setName("Sanji");
String actual = pirate.getName();

assertThat(actual).isEqualTo("Sanji");
}

@Test
void testGetDepartment() {
String actual = pirate.getDepartment();

assertThat(actual).isEqualTo("Swordsman");
}

@Test
void testSetDepartment() {
pirate.setDepartment("Cook");
String actual = pirate.getDepartment();

assertThat(actual).isEqualTo("Cook");
}

@Test
void testGetSalary() {
double actual = pirate.getSalary();

assertThat(actual).isEqualTo(900000);
}

@Test
void testSetSalary() {
pirate.setSalary(850000);
double actual = pirate.getSalary();

assertThat(actual).isEqualTo(850000);
}

@Test
void testGetDetails() {
String actual = pirate.getDetails();

assertThat(actual).isEqualTo("2 Zoro Swordsman 900000.0");
}
}
Loading