diff --git a/_1_basics/src/main/java/code/_3_in_class/Salut.java b/_1_basics/src/main/java/code/_3_in_class/Salut.java new file mode 100644 index 000000000..2f119ca69 --- /dev/null +++ b/_1_basics/src/main/java/code/_3_in_class/Salut.java @@ -0,0 +1,7 @@ +package code._3_in_class; + +public class Salut { + public static void main(String[] args) { + System.out.println("hello world!"); + } +} diff --git a/_2_oo/src/main/java/code/_3_in_class/Boxer.java b/_2_oo/src/main/java/code/_3_in_class/Boxer.java new file mode 100644 index 000000000..5f078910d --- /dev/null +++ b/_2_oo/src/main/java/code/_3_in_class/Boxer.java @@ -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(){} +} diff --git a/_2_oo/src/main/java/code/_3_in_class/BruceLee.java b/_2_oo/src/main/java/code/_3_in_class/BruceLee.java new file mode 100644 index 000000000..9b667a503 --- /dev/null +++ b/_2_oo/src/main/java/code/_3_in_class/BruceLee.java @@ -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; + } +} diff --git a/_2_oo/src/main/java/code/_3_in_class/Main.java b/_2_oo/src/main/java/code/_3_in_class/Main.java index 3b87b4563..2a65a883c 100644 --- a/_2_oo/src/main/java/code/_3_in_class/Main.java +++ b/_2_oo/src/main/java/code/_3_in_class/Main.java @@ -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); + } + } } -} \ No newline at end of file +}