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/BunaZiua.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package code._3_in_class;

public class BunaZiua {

public static void main(String[] args) { // COMMAND : psvm
System.out.println("buna");
}
}
33 changes: 33 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,33 @@
package code._3_in_class;

import java.util.Random;

public class Boxer implements IBoxer {

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


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

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

public void attack(Boxer opponent){
int defend = (this.damagePerAttack * this.defend())/100;
opponent.health = opponent.health - (this.damagePerAttack - defend);
System.out.println(this.name + " il ataca pe " + opponent.name + '\n' +
this.name + " health = " + this.health + " " + opponent.name + " health = " + opponent.health );
}

public int defend() {
Random ran = new Random();
return ran.nextInt(101);
}
}
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;

public class BruceLee extends Boxer {

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

public BruceLee(String name){
super(name);
}

public void attack(Boxer opponent) {
opponent.health = 0;
System.out.println(this.name + " il ataca pe " + opponent.name + '\n' +
this.name + " health = " + this.health + " " + opponent.name + " health = " + opponent.health );
}
}
6 changes: 6 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/IBoxer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package code._3_in_class;

public interface IBoxer {
void attack(Boxer opponent);
int defend();
}
28 changes: 28 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,36 @@
package code._3_in_class;
import javax.swing.*;
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,14);
Boxer Vasile = new Boxer("Vasile",100,10);
Boxer bruceLee = new BruceLee("Bruce Lee");
startBoxingMatch(Ion,bruceLee);
//startBoxingMatch(Ion,Vasile);
announceVictory(Ion,bruceLee);
}

private static void announceVictory(Boxer b1, Boxer b2){
if(b1.health <= 0)
System.out.println(b2.name + " a castigat.");
else
System.out.println(b1.name + " a castigat.");

}

private static void startBoxingMatch(Boxer b1, Boxer b2) {
Random ran = new Random();
int zeroOrOne = ran.nextInt(100);
while (b1.health > 0 && b2.health > 0) {
if (zeroOrOne % 2 == 0)
b1.attack(b2);
else
b2.attack(b1);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package code._3_in_class;

public class StaticExample {
static final int altaVariabila = 0; // will postpone for now
static int iStaticSauVariabilaDeClasa = 0; // keyword static -> ne lasa posibilitatea de schimbarea unei variabile
int iInstantaSauVariabilaDeInstanta = 0;

public static void main(String[] args) {
StaticExample i1 = new StaticExample();
StaticExample i2 = new StaticExample();
StaticExample i3 = new StaticExample();

i1.iStaticSauVariabilaDeClasa = 1;
i2.iInstantaSauVariabilaDeInstanta = 2;
i3.iInstantaSauVariabilaDeInstanta = 3;
System.out.println("i1.iStatic =" + i1.iInstantaSauVariabilaDeInstanta);
System.out.println("i2.iInstanta =" + i2.iInstantaSauVariabilaDeInstanta);
System.out.println("i3.iInstanta=" + i3.iInstantaSauVariabilaDeInstanta);

}

static void m() {
System.out.println("static method");
}

void m2() {
System.out.println("m2");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>_2_design_patterns_project</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>


</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package clean.code.design_patterns.requirements.DoctorRepository;

import clean.code.design_patterns.requirements.Domain.Doctor;

import java.util.List;
import java.util.NoSuchElementException;

public class CollectionIterator implements ICollectionIterator {
private List<Doctor> list;
private int position;

public CollectionIterator(List<Doctor> list) {
this.list = list;
this.position = 0;
}

@Override
public boolean hasNext() {
return position < list.size();
}

@Override
public Doctor next() {
if (hasNext()) {
Doctor nextDoctor = list.get(position);
position++;
return nextDoctor;
}
throw new NoSuchElementException("No more elements in the collection.");
}

@Override
public Doctor currentPosition() {
if (position >= 0 && position < list.size()) {
return list.get(position);
}
throw new IllegalStateException("Iterator is not pointing to a valid position.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package clean.code.design_patterns.requirements.DoctorRepository;
import java.util.ArrayList;
import java.util.List;
import clean.code.design_patterns.requirements.Domain.Doctor;

public class DoctorRepository implements ICollection {
private List<Doctor> repo;

public DoctorRepository() {
this.repo = new ArrayList<>();
}

@Override
public void add(Doctor doctor) {
this.repo.add(doctor);
}

@Override
public void remove(Doctor doctor) {
this.repo.remove(doctor);
}

@Override
public ICollectionIterator iterator() {
return new CollectionIterator(this.repo);
}

public List<Doctor> getAll() {
return this.repo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package clean.code.design_patterns.requirements.DoctorRepository;
import clean.code.design_patterns.requirements.Domain.Doctor;

public interface ICollection {
void add(Doctor doctor);
void remove(Doctor doctor);
ICollectionIterator iterator();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package clean.code.design_patterns.requirements.DoctorRepository;


import clean.code.design_patterns.requirements.Domain.Doctor;

public interface ICollectionIterator {
boolean hasNext();
Doctor next();
Doctor currentPosition();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package clean.code.design_patterns.requirements.Domain;
import java.util.Objects;

public class Doctor {
private String firstName;
private String lastName;
private String specialization;
private double salary;

public Doctor(String firstName, String lastName, String specialization, double salary) {
this.firstName = firstName;
this.lastName = lastName;
this.specialization = specialization;
this.salary = salary;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getSpecialization() {
return specialization;
}

public void setSpecialization(String specialization) {
this.specialization = specialization;
}

public double getSalary() {
return salary;
}

public void setSalary(double salary) {
this.salary = salary;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Doctor doctor = (Doctor) o;
return Objects.equals(firstName, doctor.firstName) && Objects.equals(lastName, doctor.lastName) && Objects.equals(specialization, doctor.specialization) && Objects.equals(salary, doctor.salary);
}

@Override
public int hashCode() {
return Objects.hash(firstName, lastName, specialization, salary);
}

@Override
public String toString() {
return "Dr. " + firstName + ' ' + lastName + ", " + specialization + ", has salary " + salary + "$";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package clean.code.design_patterns.requirements;

import clean.code.design_patterns.requirements.DoctorRepository.DoctorRepository;
import clean.code.design_patterns.requirements.Service.Service;
import clean.code.design_patterns.requirements.UI.UserInterface;
import clean.code.design_patterns.requirements.Validate.Validator;
public class Main {

public static void main(String[] args) {
//TODO implement your design patterns in this package

DoctorRepository repo = new DoctorRepository();
Validator validator = new Validator();
Service service = new Service(repo,validator);
UserInterface ui = new UserInterface(service);
ui.start();
}
}
}
Loading