Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stoica_Roland-Viorel #199

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class HelloWorld {
public static void main(String[] args) {

System.out.println("hello world");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void main(String[] args) {
private static void checkForXValue(int x) {
int expectedXValue = 11;

System.out.println("Guessed correctly the value of x ? - " + (x == expectedXValue));
System.out.println("Guessed correctly the value of x ? - " + (x == 11));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ private static void loopUsingWrapper() {
Instant stop2 = Instant.now();
Duration duration2 = Duration.between(start2, stop2);
System.out.println("using wrapper: " + duration2); //why is duration1 so different from duration2 ?
//durata este diferita din cauza ca aici accesam niste clase deja create prin intermediu Integer, astfel este o metoda
//apelata in contiunu creand o durata mai mare de iteratie
}

private static void loopUsingPrimitive() {
Expand Down
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 {
public static void main(String[] args) {
//psvm genereaza mainu
System.out.println("Fain");
}
}
6 changes: 6 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Arici.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package code._3_in_class;

public class Arici {
int size;
String color;
}
21 changes: 21 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,21 @@
package code._3_in_class;

public class Boxer implements IBoxer {

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

public void attack(Boxer opponent) {
opponent.health -= damagePerAttack;
};
public int defend(){
return 0;
};

public Boxer(String nume, int health, int damagePerAttack){
this.name = name;
this.health = health;
this.damagePerAttack =damagePerAttack;
}
}
12 changes: 12 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Gloves.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package code._3_in_class;

public class Gloves {
int size;
String Color;

Arici arici;
public Gloves(int size, String Color){
this.size = size;
this.Color = Color;
}
}
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 {
public void attack(Boxer opponent);
public int defend();
}
32 changes: 32 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,40 @@
package code._3_in_class;

import java.util.Random;

public class Main {

Gloves stanga;
Gloves dreapta;

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

Boxer vasileBoxer = new Boxer("Vasile", 100, 20);
Random random = new Random();

matchMaking(ionBoxer, vasileBoxer, random);
showWinner(ionBoxer);
}

private static void showWinner(Boxer ionBoxer) {
if(ionBoxer.health < 0){
System.out.println("Vasile e smecher");
} else {
System.out.println("Ion e smecher");
}
}

private static void matchMaking(Boxer ionBoxer, Boxer vasileBoxer, Random random) {
while(ionBoxer.health > 0 && vasileBoxer.health > 0 )
{
int zeroOrOne = random.nextInt(2);
if(zeroOrOne == 0){
ionBoxer.attack(vasileBoxer);
}else {
vasileBoxer.attack(ionBoxer);
}
}
}
}
6 changes: 6 additions & 0 deletions _2_oo/src/main/java/code/_3_in_class/Siret.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package code._3_in_class;

public class Siret {
int size;
String color;
}
17 changes: 17 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/Bicycle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package code._4_student_effort;

public class Bicycle {
int speed = 0;
int gear = 1;
void changeGear(int newValue){
this.gear = newValue;
}

void speedUp(int increment){
this.speed += increment;
}

void applyBrakes(int decrement){
this.speed -= decrement;
}
}
13 changes: 13 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/Bottom2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package code._4_student_effort;

public class Bottom2 extends Top {
public Bottom2(String s) {
super();
System.out.println("D");
}

public static void main(String[] args) {
new Bottom2("C");
System.out.println(" ");
}
}
2 changes: 2 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ public class Main {

public static void main(String[] args) {
//TODO put your code changes in here
//pentru a apela ce e inauntr lui Numbers
System.out.println(Numbers.Number1.getName());
}
}
14 changes: 14 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/Numbers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package code._4_student_effort;

public enum Numbers {
Number1("Hello 1"),Number2("Hello 2");

String name;
Numbers(String name){
this.name = name;
}

public String getName(){
return name;
}
}
8 changes: 8 additions & 0 deletions _2_oo/src/main/java/code/_4_student_effort/Top.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package code._4_student_effort;

public class Top {
public Top() {
System.out.println("B");
}
}

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

public class BurgerFactory {
private boolean salad;
private boolean sauce;
private String typeOfSauce;
private String typeOfMeat;

//Singelton Design pattern
public boolean getSalad(){
return this.salad;
}

public String getTypeOfSauce(){
return this.typeOfSauce;
}

public boolean getSauce(){
return this.sauce;
}

public String getTypeOfMeat(){
return this.typeOfMeat;
}
private BurgerFactory(BuilderBurgerFactory builder){
this.salad = builder.salad;
this.sauce = builder.sauce;
this.typeOfMeat = builder.typeOfMeat;
this.typeOfSauce = builder.typeOfSauce;
}

public static class BuilderBurgerFactory{
private boolean salad;
private boolean sauce;
private String typeOfSauce;
private String typeOfMeat;

//builder design patern
public BuilderBurgerFactory(String meat){
this.typeOfMeat = meat;
}

public BuilderBurgerFactory setSauce(boolean sauce, String typeOfSauce){
this.sauce = sauce;
if( sauce == true) setTypeOfSauce(typeOfSauce);
return this;
}

public BuilderBurgerFactory setTypeOfSauce(String sauce){
this.typeOfSauce = sauce;
return this;
}

public BuilderBurgerFactory setSalad(boolean salad){
this.salad = salad;
return this;
}

public BurgerFactory build(){
return new BurgerFactory(this);
}

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

public class Client1 extends Clients {

@Override
public boolean salad() {
return true;
}

@Override
public boolean sauce() {
return true;
}

@Override
public String typeOfSauce() {
return "Maioneza";
}

@Override
public String typeOfMeat() {
return "Pui";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package clean.code.design_patterns.requirements;

public class Client2 extends Clients{
@Override
public boolean salad() {
return false;
}

@Override
public boolean sauce() {
return true;
}

@Override
public String typeOfSauce() {
return "barbecue";
}

@Override
public String typeOfMeat() {
return "vita";
}
}

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

public class Client3 extends Clients{
@Override
public boolean salad() {
return true;
}

@Override
public boolean sauce() {
return false;
}

@Override
public String typeOfSauce() {
return null;
}

@Override
public String typeOfMeat() {
return "pui";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package clean.code.design_patterns.requirements;
//Template Method Pattern
public abstract class Clients {
public final void messages(){
salad();
sauce();
typeOfSauce();
typeOfMeat();
}

public abstract boolean salad();
public abstract boolean sauce();
public abstract String typeOfSauce();
public abstract String typeOfMeat();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@
public class Main {

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

Client1 client1 = new Client1();
Client2 client2 = new Client2();
Client3 client3 = new Client3();
String salataTrue = " cu salata";
String salataFalse = " fara salata";
String sosFalse = " fara sos";
long i = 5000000000L;


System.out.println("Buna ziua, bine v-am gasit la fabrica mea de burgeri digitali");
System.out.println("Se pare ca avem azi 3 clienti, sa auzim ce vrea fiecare");

System.out.print("Primul client doreste : " + client1.typeOfMeat());
if(client1.salad() == true) System.out.print(salataTrue);
else System.out.print(salataFalse);
if(client1.sauce() == true) System.out.print(" si cu " + client1.typeOfSauce());
else System.out.print(sosFalse);
System.out.println();
System.out.print("Burgerul se pregateste ");
while(i >0 ){
if ( i % 1000000000L == 0) System.out.print(". ");
i--;
}
System.out.println("");
BurgerFactory burger = new BurgerFactory.BuilderBurgerFactory(client1.typeOfMeat()).setSalad(client1.salad()).setSauce(client1.sauce(),client1.typeOfSauce()).build();
System.out.println("Burgerul s-a pregatit, pofta buna!");
}
}