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
7 changes: 7 additions & 0 deletions _1_basics/src/main/java/code/_3_in_class/Salut.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package code._3_in_class;

public class Salut {
public static void main(String[] args) {
System.out.println("hello world!");
}
}
24 changes: 24 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Boxer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package code._3_in_class;

public class Boxer {
String nume;
int health = 100;
int dammagePerAttack =10;

//constructor
public Boxer(String nume, int health, int dammagePerAttack) {
this.nume = nume;
this.health = health;
this.dammagePerAttack = dammagePerAttack;
}

public Boxer(String nume) {
this.nume = nume;
}

void attack(Boxer opponent) {
opponent.health = opponent.health - this.dammagePerAttack;
System.out.println(this.nume + "il ataca pe" + opponent.nume +"-new health is =" + opponent.health);
}
void defend(){}
}
13 changes: 13 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/BruceLee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package code._3_in_class;

public class BruceLee extends Boxer {
public BruceLee (String nume, int health, int dammagePerAttack) {
this.nume = nume;
this.health = health;
this.dammagePerAttack = dammagePerAttack;
}

public BruceLee (String nume) {
this.nume = nume;
}
}
31 changes: 30 additions & 1 deletion _2_oo/src/main/java/code/_3_in_class/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
package code._3_in_class;
import java.util.Random;

public class Main {

public static void main(String[] args) {
//TODO put your code changes in here
Boxer ion = new Boxer("ion", 100, 10);
Boxer vasile = new Boxer("vasile");


startBoxingMatch(ion, vasile);
endingResults(ion);
}

private static void endingResults(Boxer ion) {
if (ion.health <= 0) {
System.out.println("Vasile a castigat meciul");
} else {
System.out.println("Ion a castigat meciul");
}
}



private static void startBoxingMatch(Boxer ion, Boxer vasile) {
Random random = new Random();
while(ion.health >0 && vasile.health >0) {
int zeroOrOne = random.nextInt(2);
if(zeroOrOne ==0) {
ion.attack(vasile);
} else {
vasile.attack(ion);
}
}
}
}
}