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
38 changes: 38 additions & 0 deletions LABJavaIntroTotesting/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
5 changes: 5 additions & 0 deletions LABJavaIntroTotesting/.idea/.gitignore

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

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

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

14 changes: 14 additions & 0 deletions LABJavaIntroTotesting/.idea/misc.xml

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

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

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

25 changes: 25 additions & 0 deletions LABJavaIntroTotesting/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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>com.ironhack</groupId>
<artifactId>LABJavaIntroTotesting</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.11.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.ironhack.javaKeywords;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class JavaKey {
private String stringKey;
private final List<String> JAVA_KEYWORDS = 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",
"true", "false", "null");


public JavaKey(String stringKey) {
this.stringKey = stringKey;

}

public String getStringKey() {
return stringKey;
}

public List<String> getJAVA_KEYWORDS() {
return JAVA_KEYWORDS;
}

public String compareKeyString() {

String[] words = this.stringKey.split("\\s+");
List<String> foundKeyWords = new ArrayList<>();
for (String word : words) {
for (String keyword : JAVA_KEYWORDS) {
if (word.equalsIgnoreCase((keyword))) {
foundKeyWords.add(word);

}
}
}
if (foundKeyWords.isEmpty()) {
return "Doesn't found any key word.";
} else {
return "Key word found: " + foundKeyWords;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.ironhack.javaKeywords;

import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

//We ask user for a String call stringPhrase
Scanner scanner = new Scanner(System.in);
String stringPhrase = "";
boolean validInput = false;

do {
System.out.println("Please write your phrase");
if (scanner.hasNextLine()) {
stringPhrase = scanner.nextLine();
validInput = true;
} else {
System.out.println("That's not a valid input");
}
} while (!validInput);
System.out.println("Your phrase is: " + stringPhrase);
scanner.close();

JavaKey jk = new JavaKey(stringPhrase);
String foundJavKeyWords = jk.compareKeyString();
System.out.println(foundJavKeyWords);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.ironhack.oddIntegers;

import java.util.List;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {

//We ask user for a number call n
Scanner scanner = new Scanner(System.in);
int n = 0;
boolean validInput = false;

do {
System.out.println("Please write an integer");
if (scanner.hasNextInt()) {
n = scanner.nextInt();
validInput = true;
} else {
System.out.println("That's not a valid integer. Try again");
scanner.next();
}

} while (!validInput);
System.out.println("Your integer is: " + n);

scanner.close();

NListGenerator generator = new NListGenerator(n);
List<Integer> oddNumbers = generator.generateOddList();
System.out.println("Odd numbers from 0 to " + n + ": " + oddNumbers);

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.ironhack.oddIntegers;

import java.util.ArrayList;
import java.util.List;

public class NListGenerator {

private int n;
private List<Integer> nList;

public NListGenerator(int n) {
this.n = n;
}

public int getN() {
return n;
}

public List<Integer> generateOddList() {
nList = new ArrayList<>();

if (this.n < 0) {
for (int i = 0; i >= this.n; i--) {
if (i % 2 != 0) {
nList.add(i);
}
}
} else if (this.n > 0) {
for (int i = 0; i <= this.n; i++) {
if (i % 2 != 0) {
nList.add(i);
}
}
}
return nList;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.ironhack.videoGame;

public class Elf extends Player{
private int speed;

public int getSpeed() {
return speed;
}

public void setSpeed(int speed) {
this.speed = speed;
}

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

@Override
public String toString() {
return "Elf{" +
"speed=" + speed +
"} " + super.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.ironhack.videoGame;

public class Player {
private int health;
private int strength;
private int lives;

public Player(int health, int strength, int lives) {
this.health = health;
this.strength = strength;
this.lives = lives;
}

public int getHealth() {
return health;
}

public int getStrength() {
return strength;
}

public int getLives() {
return lives;
}

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

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

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

public void decrementLives() {
if (this.lives > 0) {
this.lives--;
this.health = 100; //Restore the health
}
}

public void checkHealth() {
if (this.health <= 0) {
this.decrementLives();
}
}

public String attack(Player playerToAttack) {

if (this.strength <= 0) {
return "This player cannot attack, doesn't have any strength";
}
if (playerToAttack.getLives() <= 0) {
return "The player " + playerToAttack + " is dead";
}

int newHealth = playerToAttack.getHealth() - this.strength;
playerToAttack.setHealth(newHealth);
playerToAttack.checkHealth();
playerToAttack.checkHealth();

if (playerToAttack.getLives() <= 0) {
return playerToAttack + " is dead!";
} else {
return "damage has occurred " + playerToAttack + " health: " + playerToAttack.getHealth();
}
}

@Override
public String toString() {
return "Player{" +
"health=" + health +
", strength=" + strength +
", lives=" + lives +
'}';
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ironhack.videoGame;

public class Warrior extends Player{
private int force;

public Warrior(int health, int strength, int lives, int force) {
super(health, strength, lives);
this.force = force;
}
public Elf convertToElf() {
return new Elf (this.getHealth(), this.getStrength(), this.getLives(), this.force);

}

@Override
public String toString() {
return "Warrior{" +
"force=" + force +
"} " + super.toString();
}
}
Loading