Skip to content
Open
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>lab-java-intro-to-testing</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
</dependency>
</dependencies>
</project>
21 changes: 21 additions & 0 deletions src/main/java/exercise1/Ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package exercise1;

public class Ex1 {
public static int[] getOddInts(int n) throws IllegalArgumentException {
if (n < 1) {
throw new IllegalArgumentException("the number must be greater than or equal to 1");
}

int[] oddNums = new int[(n + 1) / 2];
int index = 0;

for (int i = 1; i <= n; i++) {
if (i % 2 != 0) {
oddNums[index] = i;
index++;
}
}

return oddNums;
}
}
25 changes: 25 additions & 0 deletions src/main/java/exercise2/Ex2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package exercise2;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class Ex2 {
private static final Set<String> javaKeywords = new HashSet<>(Arrays.asList(
"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class",
"const", "continue", "default", "do", "double", "else", "enum", "extends", "final",
"finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
"interface", "long", "native", "new", "package", "private", "protected", "public",
"return", "short", "static", "strictfp", "super", "switch", "synchronized", "this",
"throw", "throws", "transient", "try", "void", "volatile", "while"
));

public static boolean hasKeyword(String str) {
for (String word : str.split("\\s+")) {
if (javaKeywords.contains(word)) {
return true;
}
}
return false;
}
}
17 changes: 17 additions & 0 deletions src/main/java/exercise3/Elf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package exercise3;

class Elf extends Player {
final int speed;

public Elf(int health, int strength, int lives, int speed) {
super(health, strength, lives);
this.speed = speed;
}

//Getters

public int getSpeed() {
return speed;
}
}

63 changes: 63 additions & 0 deletions src/main/java/exercise3/Player.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package exercise3;

abstract class Player {
private int health;
private int strength;
private int lives;
private final int initialHealth;

//Constructor
public Player(int health, int strength, int lives) {
setHealth(health);
setStrength(strength);
setLives(lives);
initialHealth = health;
}

//Getters
public int getHealth() {
return health;
}

public int getStrength() {
return strength;
}

public int getLives() {
return lives;
}

//Setters
public void setHealth(int health) {
this.health = health;
}

public void setStrength(int strength) {
this.strength = strength;
}

public void setLives(int lives) {
this.lives = lives;
}

//Methods
// Methods
public void decrementLive() {
if (lives <= 0) {
System.out.println("This character is dead");
} else {
lives--;
setHealth(initialHealth);
}
}

public void attack(Player playerToAttack) {
playerToAttack.setHealth(playerToAttack.getHealth() - strength);
}

public void checkHealth() {
if (health <= 0) {
decrementLive();
}
}
}
20 changes: 20 additions & 0 deletions src/main/java/exercise3/Warrior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package exercise3;

class Warrior extends Player {
final int force;

public Warrior(int health, int strength, int lives, int force) {
super(health, strength, lives);
this.force = force;
}

//Getter
public int getForce() {
return force;
}

// Method
public Elf convertToElf() {
return new Elf(getHealth(), getStrength(), getLives(), 0);
}
}
20 changes: 20 additions & 0 deletions src/main/java/exercise3/Wizard.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package exercise3;

class Wizard extends Player {
private String spell;

public Wizard(int health, int strength, int lives, String spell) {
super(health, strength, lives);
this.spell = spell;
}

//Getters
public String getSpell() {
return spell;
}

//Methods
public Elf convertToElf() {
return new Elf(getHealth(), getStrength(), getLives(), 0);
}
}
Loading