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

public class ClasaBunaZiua {
public static void main(String[] args) {
System.out.println("Buna ziua");
}
}
37 changes: 36 additions & 1 deletion _1_basics/src/main/java/code/_3_in_class/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,43 @@
package code._3_in_class;

import java.sql.SQLOutput;

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 = copyArray(ar);
int[] v2 =copyArray(ar);
ar[0] = 10;
v1[0] = 100;
v2[0] = 1000;


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

String s="ABC";
System.out.println(s);
s="DEF";
System.out.println(s);
}

private static int[] copyArray(int[]ar)
{
int[] copyArray=new int[ar.length];
for(int i=0;i<copyArray.length;i++)
{
copyArray[i]=ar[i];
}
return copyArray;
}
private static void displayVector(String name, int[] ar) {
System.out.print(name + " = ");
for (int i = 0; i < ar.length; i++) {
System.out.print(ar[i] + " ");
}
System.out.println();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class Main {

public static void main(String[] args) {
//TODO put your code changes in here

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

public class Address {
private String street;
private int number;
private String city;

public Address(String street, int number, String city) {
this.street = street;
this.number = number;
this.city = city;
}

public String getStreet() {
return street;
}

public void setStreet(String street) {
this.street = street;
}

public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Address- ");
sb.append("Number: ").append(number);
sb.append(" Street: ").append(street);
sb.append(" City: ").append(city);
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package clean.code.design_patterns.requirements;

public class BankTransfer implements PaymentMethod {
@Override
public void paySalary(float amount,Employee e) {
System.out.println("Employee "+e.getID()+" has received its salary ("+amount+") by using the Payment Method: Bank Transfer");
}

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

public enum Department {
HR,Software,Hardware,QA,Security,DataWarehouse;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package clean.code.design_patterns.requirements;

public class Employee {
private String name;
private int ID;
private Department department;
private Function function;
private float salary;
private int managerID;
private Address address;
private boolean sentSalary;
private PaymentMethod method;

private Employee(Builder builder) {
this.name = builder.name;
this.ID = builder.ID;
this.department = builder.department;
this.function = builder.function;
this.salary = builder.salary;
this.managerID = builder.managerID;
this.address = builder.address;
this.sentSalary = builder.sentSalary;
this.method = builder.method;
}

public String getName() {
return name;
}

public int getID() {
return ID;
}

public Department getDepartment() {
return department;
}

public Function getFunction() {
return function;
}

public float getSalary() {
return salary;
}

public int getManagerID() {
return managerID;
}

public Address getAddress() {
return address;
}

public void receiveSalary() {
if (method == null) {
System.out.println("The employee" + ID + " didn't choose any payment method for his salary");
} else if (!sentSalary) {
sentSalary = true;
method.paySalary(this.getSalary(), this);
} else {
System.out.println("Employee " + this.getID() + " has already received his salary this month");
}
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Employee- ");
sb.append(" Name: ").append(name);
sb.append(" ID: ").append(ID);
if (department != null) {
sb.append(", Department: ").append(department);
}
if (function != null) {
sb.append(", Function: ").append(function);
}
sb.append(", Salary: ").append(salary);

return sb.toString();
}

public static class Builder {
private String name;
private int ID;
private Department department;
private Function function;
private float salary;
private int managerID;
private Address address;
private boolean sentSalary;
private PaymentMethod method;

public Builder(String name, int ID, float salary, Function function) {
this.name = name;
this.ID = ID;
this.salary = salary;
this.function = function;
}

public Builder setDepartment(Department department) {
this.department = department;
return this;
}

public Builder setFunction(Function function) {
this.function = function;
return this;
}

public Builder setSalary(float salary) {
this.salary = salary;
return this;
}

public Builder setManagerID(int managerID) {
this.managerID = managerID;
return this;
}

public Builder setAddress(Address address) {
this.address = address;
return this;
}

public Builder setSentSalary(boolean sentSalary) {
this.sentSalary = sentSalary;
return this;
}

public Builder setMethod(PaymentMethod method) {
this.method = method;
return this;
}

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


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

public enum Function {
Intern,Junior,Mid,Senior,Director;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,69 @@
package clean.code.design_patterns.requirements;

import java.util.ArrayList;
import java.util.List;

public class Main {

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

List<Employee> employeeList=new ArrayList<>();
Employee e1 = new Employee.Builder("Rares", 1, 3500.45f, Function.Junior)
.setDepartment(Department.Software)
.setManagerID(2)
.setAddress(new Address("Calea Victoriei", 2, "Bucharest"))
.setMethod(new PayPal())
.build();
employeeList.add(e1);

Employee e2 = new Employee.Builder("Andrei", 2, 10000, Function.Senior)
.setDepartment(Department.Software)
.setAddress(new Address("Gheorghe Sincai", 1, "Bucharest"))
.setSentSalary(true)
.build();
employeeList.add(e2);

Employee e3 = new Employee.Builder("Marius", 3, 7500.52f, Function.Mid)
.setDepartment(Department.Hardware)
.setManagerID(2)
.build();
employeeList.add(e3);

Employee e4 = new Employee.Builder("Alex", 4, 3500, Function.Intern)
.setDepartment(Department.Hardware)
.setManagerID(3)
.setAddress(new Address("Calea Decebal", 3, "Bucharest"))
.setMethod(new PayPal())
.build();
employeeList.add(e4);

Employee e5 = new Employee.Builder("Tudor", 5, 5500.83f, Function.Junior)
.setDepartment(Department.Hardware)
.setManagerID(3)
.setSentSalary(true)
.setMethod(new BankTransfer())
.build();
employeeList.add(e5);

Employee e6 = new Employee.Builder("Ovidiu", 6, 20000, Function.Director)
.build();
employeeList.add(e6);

Employee e7 = new Employee.Builder("George", 7, 7000, Function.Junior)
.setDepartment(Department.Software)
.setManagerID(2)
.setSentSalary(true)
.setMethod(new Post())
.build();
employeeList.add(e7);

for(Employee e : employeeList){
System.out.println(e);
}

for(Employee e : employeeList){
e.receiveSalary();
}

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

public class PayPal implements PaymentMethod{
@Override
public void paySalary(float amount,Employee e) {
System.out.println("Employee "+e.getID()+" has received its salary ("+amount+") by using the Payment Method: PayPal");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package clean.code.design_patterns.requirements;

public interface PaymentMethod {
void paySalary(float amount,Employee e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package clean.code.design_patterns.requirements;

public class Post implements PaymentMethod{
@Override
public void paySalary(float amount,Employee e) {
System.out.println("Employee "+e.getID()+" has received its salary ("+amount+") by using the Payment Method: Post");
}
}