Skip to content

Commit

Permalink
Add ssource code examples
Browse files Browse the repository at this point in the history
  • Loading branch information
RadoRado committed Apr 21, 2016
1 parent 14b1118 commit fec0ad2
Show file tree
Hide file tree
Showing 24 changed files with 475 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Box.java
@@ -0,0 +1,17 @@
package com.hackbulgaria.qa.week2;

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


public class Box<T> {
private T data;

public Box(T data) { this.data = data; }
public T getData() { return data; }

public static void main(String[] args) {
Box<Integer> a = new Box<>(1);
}
}
18 changes: 18 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Entity.java
@@ -0,0 +1,18 @@
package com.hackbulgaria.qa.week2;

public abstract class Entity {
private String id;

protected String getId() { return id; }

public abstract String getIdentifier();

public Entity(String id) {
this.id = id;
}

@Override
public String toString() {
return getIdentifier();
}
}
9 changes: 9 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Ivo.java
@@ -0,0 +1,9 @@
package com.hackbulgaria.qa.week2;

public abstract class Ivo extends Panda {
@Override
public void eat() {
// TODO Auto-generated method stub

}
}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Magche.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2;

public class Magche extends Ivo {

}
31 changes: 31 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Main.java
@@ -0,0 +1,31 @@
package com.hackbulgaria.qa.week2;

import java.util.ArrayList;
import java.util.Collections;

public class Main {
public static void printArray(Object[] arr) {
StringBuilder b = new StringBuilder();
b.append("[");
for (int i = 0; i < arr.length; i++) {
b.append(arr[i].toString());

if(i != arr.length - 1) {
b.append(", ");
}
}

b.append("]");
System.out.println(b.toString());
}

public static void main(String[] args) {
Student ivo = new Student("8");

ArrayList<Entity> everything = new ArrayList<>();
everything.add(new Student("1"));
everything.add(new Teacher("2"));
everything.add(ivo);
System.out.println(everything);
}
}
9 changes: 9 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Panda.java
@@ -0,0 +1,9 @@
package com.hackbulgaria.qa.week2;


public abstract class Panda {

public Panda() {}
public abstract void eat();

}
61 changes: 61 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Person.java
@@ -0,0 +1,61 @@
package com.hackbulgaria.qa.week2;

public class Person implements Comparable<Person> {
private String name;
private int age;

public Person(String name, int age) {
this.name = name;
this.age = age;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

public String toString() {
StringBuilder b = new StringBuilder();

b.append("(");
b.append(name);
b.append(", ");
b.append(age);
b.append(")");

return b.toString();
}

@Override
public int compareTo(Person o) {
if(this.age == o.age) {
return 0;
}

if(this.age < o.age) {
return -1;
}

return 1;
}
}










16 changes: 16 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/PersonComparator.java
@@ -0,0 +1,16 @@
package com.hackbulgaria.qa.week2;

import java.util.Comparator;

public class PersonComparator implements Comparator<Person>{

@Override
public int compare(Person o1, Person o2) {
if(o1.getAge() == o2.getAge()) {
return o1.getName().compareTo(o2.getName());
}

return o1.compareTo(o2);
}

}
18 changes: 18 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/PythonRunner.java
@@ -0,0 +1,18 @@
package com.hackbulgaria.qa.week2;

public class PythonRunner extends Runner {
public PythonRunner(String code, String test) {
super(code, test);
}

public void lint() {}
public void compile() {}

public void execute() {
// Пусни python програмата в OS–а
// Заедно с тестовете и кода
// Гледай за някакви неща / while true / fork-loops и т.н
// Вземи резултата
result = "OK";
}
}
12 changes: 12 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/RealPythonRunner.java
@@ -0,0 +1,12 @@
package com.hackbulgaria.qa.week2;

public class RealPythonRunner extends PythonRunner {
public RealPythonRunner(String code, String test) {
super(code, test);
}
@Override
public void execute() {
super.execute();
result = "NOT OK";
}
}
24 changes: 24 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Runner.java
@@ -0,0 +1,24 @@
package com.hackbulgaria.qa.week2;

public abstract class Runner {
protected String result;
protected String code;
protected String test;

public Runner(String code, String test) {
this.code = code;
this.test = test;
}

public String run() {
lint();
compile();
execute();

return result;
}

public abstract void lint();
public abstract void compile();
public abstract void execute();
}
32 changes: 32 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/SomeClass.java
@@ -0,0 +1,32 @@
package com.hackbulgaria.qa.week2;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;

public class SomeClass {

public static void main(String[] args) {
Path path = Paths.get("/home/radorado/code/Loki/R.md");

try {
List<String> lines = Files.readAllLines(path);
System.out.println(lines);
} catch (NoSuchFileException fnfe) {
System.out.println("File not found: " + fnfe.getMessage());
System.out
.println("Please ensure that you have created the file, before running again.");
fnfe.printStackTrace();

} catch (IOException e) {
System.out.println(e.toString());
System.out.println("Here");
} catch(final Exception e) {
throw e;
}
}
}
12 changes: 12 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Student.java
@@ -0,0 +1,12 @@
package com.hackbulgaria.qa.week2;

public class Student extends Entity {
public Student(String identifier) {
super(identifier);
}

@Override
public String getIdentifier() {
return "Student::" + getId();
}
}
14 changes: 14 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/Teacher.java
@@ -0,0 +1,14 @@
package com.hackbulgaria.qa.week2;

public class Teacher extends Entity {

public Teacher(String identifier) {
super(identifier);
}

@Override
public String getIdentifier() {
return "Teacher::" + getId();
}

}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/summary/A.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2.summary;

public class A extends B implements C, D {

}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/summary/B.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2.summary;

public class B {

}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/summary/C.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2.summary;

public interface C {

}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/summary/D.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2.summary;

public interface D {

}
5 changes: 5 additions & 0 deletions lesson00/src/com/hackbulgaria/qa/week2/summary/E.java
@@ -0,0 +1,5 @@
package com.hackbulgaria.qa.week2.summary;

public class E extends A {

}
12 changes: 12 additions & 0 deletions lesson00/src/com/hackbulgaria/week2/tdd/BankAccount.java
@@ -0,0 +1,12 @@
package com.hackbulgaria.week2.tdd;

import java.util.Currency;

import javax.transaction.InvalidTransactionException;

public interface BankAccount {
public Currency getCurrency();
public Integer getBalance();
public void deposit(Integer amount);
public void withdraw(Integer amount) throws NotEnoughMoney;
}
41 changes: 41 additions & 0 deletions lesson00/src/com/hackbulgaria/week2/tdd/BankAccountImpl.java
@@ -0,0 +1,41 @@
package com.hackbulgaria.week2.tdd;

import java.util.Currency;

public class BankAccountImpl implements BankAccount {

private int currentBalance;

public BankAccountImpl() {
this(0);
}

public BankAccountImpl(int initialAmount) {
this.currentBalance = initialAmount;
}

@Override
public Currency getCurrency() {
return Currency.getInstance("BGN");
}

@Override
public Integer getBalance() {
return currentBalance;
}

@Override
public void deposit(Integer amount) {
currentBalance += amount;
}

@Override
public void withdraw(Integer amount) throws NotEnoughMoney {
if(currentBalance - amount < 0) {
throw new NotEnoughMoney();
}

currentBalance -= amount;
}

}

0 comments on commit fec0ad2

Please sign in to comment.