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: 0 additions & 8 deletions _2_oo/src/main/java/code/_4_student_effort/Main.java

This file was deleted.

Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/src/BoxingMatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
public class BoxingMatch {
private Fighter fighter1;
private Fighter fighter2;

public BoxingMatch(Fighter f1, Fighter f2) {
this.fighter1 = f1;
this.fighter2 = f2;
}
public String fight(){
while(fighter1.health > 0 && fighter2.health > 0){
fighter1.attack(fighter2);
fighter2.attack(fighter1);
}
if(fighter1.health <= 0){
return fighter2.name;
}else{
return fighter1.name;
}
}

public static void main(String[] args) {
Fighter f1 = new Fighter("Fighter 1", 100, 15);
Fighter f2 = new Fighter("Fighter 2", 100, 30);

BoxingMatch boxingMatch = new BoxingMatch(f1,f2);

System.out.println("The winner is: " + boxingMatch.fight());
}
}
19 changes: 19 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/src/Fighter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Fighter {
public String name;
public int health;
public double damagePerAttack;

public Fighter(String name, int health, double damagePerAttack) {
this.name = name;
if(health > 100 || health <= 0) {
this.health = 100;
}else{
this.health = health;
}
this.damagePerAttack = damagePerAttack;
}

public void attack(Fighter opponent){
opponent.health -= this.damagePerAttack;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package clean.code.design_patterns.requirements;

public class Car {
private final Object carManufacturer;

private enum carManufacturer{
BMW, Audi, Deimler, Ford, Porsche, Lamborghini
}
private String carModel;
private int numberOfWheels;
private int numberOfSeats;
private String engineModel;
private String carColor;
private boolean navigation;
private boolean bluetooth;
private boolean adaptiveCruiseControl;

public Object getCarManufacturer() { return carManufacturer; }
public String getCarModel() { return carModel; }
public int getNumberOfWheels() { return numberOfWheels; }
public int getNumberOfSeats() { return numberOfSeats; }

public String withEngineModel() { return engineModel;}
public String withCarColor() { return carColor;}
public boolean withNavigation() { return navigation;}
public boolean withBluetooth() { return bluetooth;}
public boolean withAdaptiveCruiseControl() { return adaptiveCruiseControl;}

private Car(Builder builder){
this.carManufacturer = builder.carManufacturer;
this.carModel = builder.carModel;
this.numberOfWheels = builder.numberOfWheels;
this.numberOfSeats = builder.numberOfSeats;
this.engineModel = builder.engineModel;
this.carColor = builder.carColor;
this.navigation = builder.navigation;
this.bluetooth = builder.bluetooth;
this.adaptiveCruiseControl = builder.adaptiveCruiseControl;
}

public static class Builder{
private final Object carManufacturer;

private enum carManufacturer{
BMW, Audi, Deimler, Ford, Porsche, Lamborghini
}
private String carModel;
private int numberOfWheels;
private int numberOfSeats;

private String engineModel;
private String carColor;
private boolean navigation;
private boolean bluetooth;
private boolean adaptiveCruiseControl;

public Builder(String carManufacturer,String carModel,int numberOfWheels,int numberOfSeats){
this.carManufacturer = carManufacturer;
this.carModel = carModel;
if(numberOfWheels != 2 && numberOfWheels != 3 && numberOfWheels != 4 && numberOfSeats != 2
&& numberOfSeats != 3 && numberOfSeats != 4 && numberOfSeats != 8){
this.numberOfWheels = 4;
this.numberOfSeats = 4;
}
else{
this.numberOfWheels = numberOfWheels;
this.numberOfSeats = numberOfSeats;
}
}

public Builder withEngineModel(String engineModel){
this.engineModel = engineModel;
return this;
}

public Builder withCarColor(String carColor){
this.carColor = carColor;
return this;
}

public Builder withNavigation(boolean navigation){
this.navigation = navigation;
return this;
}

public Builder withBluetooth(boolean bluetooth){
this.bluetooth = bluetooth;
return this;
}

public Builder withAdaptiveCruiseControl(boolean adaptiveCruiseControl){
this.adaptiveCruiseControl = adaptiveCruiseControl;
return this;
}

public Object getCarManufacturer() { return carManufacturer; }
public String getCarModel() { return carModel; }
public int getNumberOfWheels() { return numberOfWheels; }
public int getNumberOfSeats() { return numberOfSeats; }
public String getEngineModel() { return engineModel; }
public String getCarColor() { return carColor; }
public boolean isNavigation() { return navigation; }
public boolean isBluetooth() { return bluetooth; }
public boolean isAdaptiveCruiseControl() { return adaptiveCruiseControl; }

public Car buildCar(){
return new Car(this);
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package clean.code.design_patterns.requirements;

import java.util.*;

public class CarShowInit {

private final adaptSeats seats = new adaptSeats();
private final ArrayList<Car> carList = new ArrayList<Car>();

private static final CarShowInit carShow = new CarShowInit();
private CarShowInit() {}
public static CarShowInit getInstance(){
return carShow;
}

public void addCarToShow(Car car){
this.carList.add(car);
}
public void setSeats(int seatSet){
seats.setSeatsNumber(seatSet);
seats.resizeNumberOfPeopleAndSeats();
}

public void presentCars(){
System.out.println("\nCars added to the show:\n");
int i = 1;
for(Car o : this.carList){
System.out.println("Car #" + i);
System.out.println(o.getCarManufacturer() + " " + o.getCarModel());
System.out.println("Wheels: " + o.getNumberOfWheels());
System.out.println("Seats: " + o.getNumberOfSeats());
System.out.println("Engine Model: " + o.withEngineModel());
System.out.println("Color: " + o.withCarColor());
System.out.println("Navigation: " + o.withNavigation());
System.out.println("Bluetooth: " + o.withBluetooth());
System.out.println("Adaptive Cruise Control: " + o.withAdaptiveCruiseControl() + "\n");
i++;
}

System.out.println("\nEnjoy watching them!");
}

public static void main(String[] args) {

CarShowInit show = getInstance();
show.setSeats(6000);
Car car1 = new Car.Builder("Audi","A8",4,4).withCarColor("Green").withBluetooth(true).withNavigation(true).buildCar();
Car car2 = new Car.Builder("BMW","i8",4,4).withCarColor("Green").withEngineModel("ALH").withBluetooth(true).withNavigation(true).buildCar();
show.addCarToShow(car1);
show.addCarToShow(car2);
show.presentCars();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package clean.code.design_patterns.requirements;

import java.util.Random;

class People {
private int peopleAtShow;
public People(){
Random r = new Random();
int randomNumberOfPeople = (int)r.nextInt(50000);
this.peopleAtShow = randomNumberOfPeople;
}

public int getPeopleAtShow(){return peopleAtShow;}
public void setPeople(int people){
this.peopleAtShow = people;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package clean.code.design_patterns.requirements;

public class Seats {
public People getPeopleAtShow(){
return new People();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package clean.code.design_patterns.requirements;

public interface SeatsAdapter {
public People resizeNumberOfPeopleAndSeats();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package clean.code.design_patterns.requirements;

public class adaptSeats extends Seats implements SeatsAdapter {
private int seatsNumber;

public adaptSeats(){
this.seatsNumber = 0;
}

public adaptSeats setSeatsNumber(int seats){
this.seatsNumber = seats;
return this;
}

public People adaptNumberOfSeatsAndPeople(People p){
if(p.getPeopleAtShow() > this.seatsNumber){
int persons = p.getPeopleAtShow();

System.out.println("\nThere are less seats (" + this.seatsNumber + ") than people (" + persons + ") at the show!" +
"\nAdjusting the number of seats and people...\n");

persons /= 2;
this.seatsNumber += (persons-this.seatsNumber);
p.setPeople(persons);

System.out.println("After the adjust:\nSeats: " + this.seatsNumber + "\nParticipants: " + persons);
}else{
System.out.println("\nThere are enough seats!\nSeats: " + this.seatsNumber + "\nParticipants: " + p.getPeopleAtShow());
}
return p;
}
@Override
public People resizeNumberOfPeopleAndSeats(){
return adaptNumberOfSeatsAndPeople(getPeopleAtShow());
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.