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

public class ClasaBunaZiua {
//psvm
public static void main(String[] args) {
System.out.println("Buna ziua");
}
}
18 changes: 18 additions & 0 deletions _1_basics/src/main/java/code/_3_in_class/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,23 @@ public class Main {

public static void main(String[] args) {
//TODO put your code changes in here
int[] ar = new int[] {1, 2, 3};
int[] v1 = ar;
int[] v2 = ar;
ar[0] = 10;
v1[0] = 100;
v2[0] = 1000;

displayVector("arr",ar);
displayVector("v1",v1);
displayVector("v2",v2);
}

public static void displayVector(String name, int[] arr) {
System.out.println(name + " = ");
for(int i = 0; i < arr.length; i++){
System.out.println(arr[i]+" ");
}
System.out.println();
}
}
30 changes: 30 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,30 @@
package code._3_in_class;

public class Boxer {

String nume;
int health = 100;
int damagePerAttack = 10;



public Boxer(String nume, int health, int damagePerAttack) {
this.nume = nume;
this.health = health;
this.damagePerAttack = damagePerAttack;
}

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


void attack(Boxer opponent){
opponent.health = opponent.health - this.damagePerAttack;
System.out.println(this.nume + " il ataca pe "+ opponent.nume+" - new health is: "+ this.health);
}
void defend(){

}

}
18 changes: 18 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,18 @@
package code._3_in_class;

import javax.swing.*;

public class BruceLee extends Boxer {

public BruceLee(String nume, int health, int damagePerAttack) {
super(nume, health, damagePerAttack);
}

public BruceLee(String nume) {
super(nume);
}
void attack(Boxer opponent) {
opponent.health = 0;
System.out.println(this.nume + " il ataca pe "+ opponent.nume+" - new health is: "+ this.health);
}
}
26 changes: 26 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,34 @@
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");
Boxer bruceLee = new BruceLee("bruce lee");
startBoxingMatch(ion, bruceLee);
announceVictory(ion, bruceLee);
}

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);
}
}
}
private static void announceVictory(Boxer b01, Boxer b02) {
if (b01.health <= 0) {
System.out.println(b02.nume +" a castigat");
} else {
System.out.println(b01.nume +" a castigat");
}
}
}