├── README.md ├── numbers.txt ├── v1 ├── Calculator.java └── Main.java ├── v2 ├── CMDLineInput.java ├── Calculator.java ├── Inputs.java └── Main.java ├── v3 ├── Calculator.java ├── Main.java ├── Repository │ ├── FileNumberRepository.java │ └── NumberRepository.java └── input │ ├── CMDLineInput.java │ └── Inputs.java ├── v4 ├── Main.java ├── Repository │ ├── FileNumberRepository.java │ └── NumberRepository.java ├── input │ ├── CMDLineInput.java │ └── Inputs.java └── operation │ ├── Addoperation.java │ ├── Divoperation.java │ ├── Muloperation.java │ ├── Operation.java │ └── SubOperation.java ├── v5 ├── Main.java ├── Repository │ ├── FileNumberRepository.java │ └── NumberRepository.java ├── input │ ├── CMDLineInput.java │ └── Inputs.java ├── operation │ ├── Addoperation.java │ ├── Divoperation.java │ ├── Muloperation.java │ ├── Operation.java │ └── SubOperation.java └── output │ ├── ConsoleOutput.java │ └── Outputs.java ├── v6 ├── Main.java ├── Repository │ ├── FileNumberRepository.java │ └── NumberRepository.java ├── factory │ ├── Factory.java │ └── ObjectOperationFactory.java ├── input │ ├── CMDLineInput.java │ └── Inputs.java ├── operation │ ├── Addoperation.java │ ├── Divoperation.java │ ├── Muloperation.java │ ├── Operation.java │ └── SubOperation.java └── output │ ├── ConsoleOutput.java │ └── Outputs.java ├── v7 ├── Main.java ├── Repository │ ├── FileNumberRepository.java │ └── NumberRepository.java ├── factory │ ├── Factory.java │ └── OperationFactory.java ├── input │ ├── CMDLineInput.java │ └── Inputs.java ├── operation │ ├── Addoperation.java │ ├── Divoperation.java │ ├── Muloperation.java │ ├── Operation.java │ └── SubOperation.java └── output │ ├── ConsoleOutput.java │ └── Outputs.java └── v8 ├── Main.java ├── Repository ├── DatabaseNumberRepository.java ├── FileNumberRepository.java └── NumberRepository.java ├── factory ├── Factory.java └── ObjectOperationFactory.java ├── input ├── CMDLineInput.java └── Inputs.java ├── operation ├── Addoperation.java ├── Divoperation.java ├── Muloperation.java ├── Operation.java └── SubOperation.java └── output ├── ConsoleOutput.java ├── GuiOutput.java └── Outputs.java /README.md: -------------------------------------------------------------------------------- 1 | # Java-Calculator 2 | This is my java calculator app that i correct with the version 3 | 4 | I follow the solid principle step by step 5 | This is the practical section of the software construction 6 | -------------------------------------------------------------------------------- /numbers.txt: -------------------------------------------------------------------------------- 1 | 20.0 10.0 -------------------------------------------------------------------------------- /v1/Calculator.java: -------------------------------------------------------------------------------- 1 | package com.company.v1; 2 | 3 | public class Calculator { 4 | 5 | private double a; 6 | private double b; 7 | 8 | public Calculator(double a, double b) { 9 | this.a = a; 10 | this.b = b; 11 | } 12 | 13 | public double getA() { 14 | return a; 15 | } 16 | 17 | public void setA(int a) { 18 | this.a = a; 19 | } 20 | 21 | public double getB() { 22 | return b; 23 | } 24 | 25 | public void setB(int b) { 26 | this.b = b; 27 | } 28 | 29 | public void add(){ 30 | System.out.println(a+b); 31 | } 32 | public void sub(){ 33 | System.out.println(a-b); 34 | } 35 | public void mul(){ 36 | System.out.println(a*b); 37 | } 38 | public void div(){ 39 | System.out.println(a/b); 40 | } 41 | 42 | 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /v1/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v1; 10 | 11 | import java.io.FileNotFoundException; 12 | import java.io.FileReader; 13 | import java.util.Scanner; 14 | 15 | public class Main { 16 | 17 | public static void main(String[] args) { 18 | Scanner inFile = null; 19 | try { 20 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 21 | } catch (FileNotFoundException e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | double A,B; 26 | 27 | A = inFile.nextDouble(); 28 | B = inFile.nextDouble(); 29 | 30 | Calculator cal = new Calculator(A,B); 31 | 32 | switch(args[0]){ 33 | case "add": 34 | cal.add(); 35 | break; 36 | case "sub": 37 | cal.sub(); 38 | break; 39 | case "mul": 40 | cal.mul(); 41 | break; 42 | case "div": 43 | cal.div(); 44 | break; 45 | default: 46 | System.out.println("Sorry that is not a function of this calculator"); 47 | 48 | 49 | } 50 | 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /v2/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v2; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /v2/Calculator.java: -------------------------------------------------------------------------------- 1 | package com.company.v2; 2 | 3 | public class Calculator { 4 | 5 | private double a; 6 | private double b; 7 | 8 | public Calculator(double a, double b) { 9 | this.a = a; 10 | this.b = b; 11 | } 12 | 13 | public double getA() { 14 | return a; 15 | } 16 | 17 | public void setA(int a) { 18 | this.a = a; 19 | } 20 | 21 | public double getB() { 22 | return b; 23 | } 24 | 25 | public void setB(int b) { 26 | this.b = b; 27 | } 28 | 29 | public void add(){ 30 | System.out.println(a+b); 31 | } 32 | public void sub(){ 33 | System.out.println(a-b); 34 | } 35 | public void mul(){ 36 | System.out.println(a*b); 37 | } 38 | public void div(){ 39 | System.out.println(a/b); 40 | } 41 | 42 | 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /v2/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v2; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | } 7 | -------------------------------------------------------------------------------- /v2/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v2; 10 | 11 | import java.io.FileNotFoundException; 12 | import java.io.FileReader; 13 | import java.util.Scanner; 14 | 15 | public class Main { 16 | 17 | public static void main(String[] args) { 18 | 19 | Scanner inFile = null; 20 | 21 | Inputs input = new CMDLineInput(args); 22 | String operation = input.read(); 23 | 24 | try { 25 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 26 | } catch (FileNotFoundException e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | double A,B; 31 | 32 | A = inFile.nextDouble(); 33 | B = inFile.nextDouble(); 34 | 35 | Calculator cal = new Calculator(A,B); 36 | 37 | switch(operation){ 38 | case "add": 39 | cal.add(); 40 | break; 41 | case "sub": 42 | cal.sub(); 43 | break; 44 | case "mul": 45 | cal.mul(); 46 | break; 47 | case "div": 48 | cal.div(); 49 | break; 50 | default: 51 | System.out.println("Sorry that is not a function of this calculator"); 52 | 53 | 54 | } 55 | 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /v3/Calculator.java: -------------------------------------------------------------------------------- 1 | package com.company.v3; 2 | 3 | public class Calculator { 4 | 5 | private double a; 6 | private double b; 7 | 8 | public Calculator(double a, double b) { 9 | this.a = a; 10 | this.b = b; 11 | } 12 | 13 | public double getA() { 14 | return a; 15 | } 16 | 17 | public void setA(int a) { 18 | this.a = a; 19 | } 20 | 21 | public double getB() { 22 | return b; 23 | } 24 | 25 | public void setB(int b) { 26 | this.b = b; 27 | } 28 | 29 | public void add(){ 30 | System.out.println(a+b); 31 | } 32 | public void sub(){ 33 | System.out.println(a-b); 34 | } 35 | public void mul(){ 36 | System.out.println(a*b); 37 | } 38 | public void div(){ 39 | System.out.println(a/b); 40 | } 41 | 42 | 43 | 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /v3/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v3; 10 | 11 | import com.company.v3.Repository.FileNumberRepository; 12 | import com.company.v3.Repository.NumberRepository; 13 | import com.company.v3.input.CMDLineInput; 14 | import com.company.v3.input.Inputs; 15 | 16 | import java.io.FileNotFoundException; 17 | import java.io.FileReader; 18 | import java.util.List; 19 | import java.util.Scanner; 20 | 21 | public class Main { 22 | 23 | public static void main(String[] args) { 24 | 25 | Scanner inFile = null; 26 | 27 | Inputs input = new CMDLineInput(args); 28 | String operation = input.read(); 29 | 30 | NumberRepository numberRepository = new FileNumberRepository(); 31 | List inputNumbers = numberRepository.read(); 32 | 33 | 34 | Calculator cal = new Calculator(inputNumbers.get(0),inputNumbers.get(1)); 35 | 36 | switch(operation){ 37 | case "add": 38 | cal.add(); 39 | break; 40 | case "sub": 41 | cal.sub(); 42 | break; 43 | case "mul": 44 | cal.mul(); 45 | break; 46 | case "div": 47 | cal.div(); 48 | break; 49 | default: 50 | System.out.println("Sorry that is not a function of this calculator"); 51 | 52 | 53 | } 54 | 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /v3/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v3.Repository; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileReader; 6 | import java.io.IOException; 7 | import java.nio.file.Files; 8 | import java.nio.file.Paths; 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Scanner; 12 | 13 | public class FileNumberRepository implements NumberRepository { 14 | 15 | 16 | @Override 17 | public List read() { 18 | 19 | List inputNumber = new ArrayList<>(); 20 | List inputNumberstr = null; 21 | 22 | Scanner inFile = null; 23 | 24 | try { 25 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 26 | } catch (FileNotFoundException e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | 31 | 32 | for (int i = 0;i<2; i++) { 33 | inputNumber.add( inFile.nextDouble()); 34 | } 35 | 36 | 37 | return inputNumber; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /v3/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v3.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v3/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v3.input; 2 | 3 | import com.company.v3.input.Inputs; 4 | 5 | public class CMDLineInput implements Inputs { 6 | 7 | private String args[]; 8 | 9 | public CMDLineInput(String args[]){ 10 | this.args = args; 11 | } 12 | 13 | 14 | @Override 15 | public String read() { 16 | /* String operation = args[0];//read the first argument 17 | return operation;*/ 18 | 19 | return args[0]; //read and return the first argument 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /v3/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v3.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | } 7 | -------------------------------------------------------------------------------- /v4/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v4; 10 | 11 | 12 | import com.company.v4.Repository.FileNumberRepository; 13 | import com.company.v4.Repository.NumberRepository; 14 | import com.company.v4.input.CMDLineInput; 15 | import com.company.v4.input.Inputs; 16 | import com.company.v4.operation.*; 17 | 18 | import java.io.FileNotFoundException; 19 | import java.io.FileReader; 20 | import java.util.List; 21 | import java.util.Scanner; 22 | 23 | public class Main { 24 | 25 | public static void main(String[] args) { 26 | 27 | Scanner inFile = null; 28 | 29 | Inputs input = new CMDLineInput(args); 30 | String operator = input.read(); 31 | 32 | NumberRepository numberRepository = new FileNumberRepository(); 33 | List inputNumbers = numberRepository.read(); 34 | 35 | 36 | Operation operation = null; 37 | 38 | switch(operator){ 39 | case "add": 40 | operation = new Addoperation(inputNumbers.get(0),inputNumbers.get(1)); 41 | break; 42 | case "sub": 43 | operation = new SubOperation(inputNumbers.get(0),inputNumbers.get(1)); 44 | break; 45 | case "mul": 46 | operation = new Muloperation(inputNumbers.get(0),inputNumbers.get(1)); 47 | break; 48 | case "div": 49 | operation = new Divoperation(inputNumbers.get(0),inputNumbers.get(1)); 50 | break; 51 | default: 52 | System.out.println("Sorry that is not a function of this calculator"); 53 | } 54 | 55 | System.out.println("Answer for "+operator+" is: "+ operation.perform()); 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /v4/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.Repository; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | 9 | public class FileNumberRepository implements NumberRepository { 10 | 11 | 12 | @Override 13 | public List read() { 14 | 15 | List inputNumber = new ArrayList<>(); 16 | List inputNumberstr = null; 17 | 18 | Scanner inFile = null; 19 | 20 | try { 21 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 22 | } catch (FileNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | 27 | 28 | for (int i = 0;i<2; i++) { 29 | inputNumber.add( inFile.nextDouble()); 30 | } 31 | 32 | 33 | return inputNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /v4/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v4/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.input; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | 20 | public static interface Inputs { 21 | 22 | String read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v4/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | 7 | class CMDLineInput implements com.company.v4.input.CMDLineInput.Inputs { 8 | 9 | private String args[]; 10 | 11 | public CMDLineInput(String args[]){ 12 | this.args = args; 13 | } 14 | 15 | 16 | @Override 17 | public String read() { 18 | /* String operation = args[0];//read the first argument 19 | return operation;*/ 20 | 21 | return args[0]; //read and return the first argument 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v4/operation/Addoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.operation; 2 | 3 | public class Addoperation implements Operation{ 4 | private final double a; 5 | private final double b; 6 | 7 | public Addoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a+b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v4/operation/Divoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.operation; 2 | 3 | public class Divoperation implements Operation{ 4 | private final double a; 5 | private final double b; 6 | 7 | public Divoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | @Override 12 | public double perform() { 13 | 14 | return a/b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v4/operation/Muloperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.operation; 2 | 3 | public class Muloperation implements Operation{ 4 | private final double a; 5 | private final double b; 6 | 7 | public Muloperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a*b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v4/operation/Operation.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.operation; 2 | 3 | public interface Operation { 4 | 5 | public double perform(); 6 | } 7 | -------------------------------------------------------------------------------- /v4/operation/SubOperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v4.operation; 2 | 3 | public class SubOperation implements Operation{ 4 | private final double a; 5 | private final double b; 6 | 7 | public SubOperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a-b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v5/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v5; 10 | 11 | 12 | import com.company.v5.Repository.FileNumberRepository; 13 | import com.company.v5.Repository.NumberRepository; 14 | import com.company.v5.input.CMDLineInput; 15 | import com.company.v5.input.Inputs; 16 | import com.company.v5.operation.*; 17 | import com.company.v5.output.ConsoleOutput; 18 | import com.company.v5.output.Outputs; 19 | 20 | import java.util.List; 21 | import java.util.Scanner; 22 | 23 | public class Main { 24 | 25 | public static void main(String[] args) { 26 | 27 | Scanner inFile = null; 28 | 29 | Inputs input = new CMDLineInput(args); 30 | String operator = input.read(); 31 | 32 | NumberRepository numberRepository = new FileNumberRepository(); 33 | List inputNumbers = numberRepository.read(); 34 | 35 | 36 | Operation operation = null; 37 | 38 | switch(operator){ 39 | case "add": 40 | operation = new Addoperation(inputNumbers.get(0),inputNumbers.get(1)); 41 | break; 42 | case "sub": 43 | operation = new SubOperation(inputNumbers.get(0),inputNumbers.get(1)); 44 | break; 45 | case "mul": 46 | operation = new Muloperation(inputNumbers.get(0),inputNumbers.get(1)); 47 | break; 48 | case "div": 49 | operation = new Divoperation(inputNumbers.get(0),inputNumbers.get(1)); 50 | break; 51 | default: 52 | System.out.println("Sorry that is not a function of this calculator"); 53 | } 54 | 55 | Outputs output = new ConsoleOutput(); 56 | output.show("Answer for "+operator+" is: "+ operation.perform()); 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /v5/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.Repository; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | 9 | public class FileNumberRepository implements NumberRepository { 10 | 11 | 12 | @Override 13 | public List read() { 14 | 15 | List inputNumber = new ArrayList<>(); 16 | List inputNumberstr = null; 17 | 18 | Scanner inFile = null; 19 | 20 | try { 21 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 22 | } catch (FileNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | 27 | 28 | for (int i = 0;i<2; i++) { 29 | inputNumber.add( inFile.nextDouble()); 30 | } 31 | 32 | 33 | return inputNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /v5/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v5/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.input; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | 20 | public static interface Inputs { 21 | 22 | String read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v5/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | 7 | class CMDLineInput implements com.company.v5.input.CMDLineInput.Inputs { 8 | 9 | private String args[]; 10 | 11 | public CMDLineInput(String args[]){ 12 | this.args = args; 13 | } 14 | 15 | 16 | @Override 17 | public String read() { 18 | /* String operation = args[0];//read the first argument 19 | return operation;*/ 20 | 21 | return args[0]; //read and return the first argument 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v5/operation/Addoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.operation; 2 | 3 | public class Addoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Addoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a+b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v5/operation/Divoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.operation; 2 | 3 | public class Divoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Divoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | @Override 12 | public double perform() { 13 | 14 | return a/b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v5/operation/Muloperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.operation; 2 | 3 | public class Muloperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Muloperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a*b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v5/operation/Operation.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.operation; 2 | 3 | public interface Operation { 4 | 5 | public double perform(); 6 | } 7 | -------------------------------------------------------------------------------- /v5/operation/SubOperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.operation; 2 | 3 | public class SubOperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public SubOperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a-b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v5/output/ConsoleOutput.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.output; 2 | 3 | public class ConsoleOutput implements Outputs { 4 | @Override 5 | public void show(String text) { 6 | System.out.println(text); 7 | } 8 | } 9 | //factory design pattern -------------------------------------------------------------------------------- /v5/output/Outputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v5.output; 2 | 3 | public interface Outputs { 4 | public void show(String text); 5 | } 6 | -------------------------------------------------------------------------------- /v6/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v6; 10 | 11 | 12 | import com.company.v6.Repository.FileNumberRepository; 13 | import com.company.v6.Repository.NumberRepository; 14 | import com.company.v6.factory.Factory; 15 | import com.company.v6.factory.ObjectOperationFactory; 16 | import com.company.v6.input.CMDLineInput; 17 | import com.company.v6.input.Inputs; 18 | import com.company.v6.operation.*; 19 | import com.company.v6.output.ConsoleOutput; 20 | import com.company.v6.output.Outputs; 21 | 22 | import java.util.List; 23 | import java.util.Scanner; 24 | 25 | public class Main { 26 | 27 | public static void main(String[] args) { 28 | 29 | Scanner inFile = null; 30 | 31 | Inputs input = new CMDLineInput(args); 32 | String operator = input.read(); 33 | 34 | NumberRepository numberRepository = new FileNumberRepository(); 35 | List inputNumbers = numberRepository.read(); 36 | 37 | 38 | Operation operation = null; 39 | 40 | Factory factoryobject = new ObjectOperationFactory(inputNumbers,operator); 41 | operation = (Operation) factoryobject.getInstance(); 42 | 43 | Outputs output = new ConsoleOutput(); 44 | output.show("Answer for "+operator+" is: "+ operation.perform()); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /v6/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.Repository; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | 9 | public class FileNumberRepository implements NumberRepository { 10 | 11 | 12 | @Override 13 | public List read() { 14 | 15 | List inputNumber = new ArrayList<>(); 16 | List inputNumberstr = null; 17 | 18 | Scanner inFile = null; 19 | 20 | try { 21 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 22 | } catch (FileNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | 27 | 28 | for (int i = 0;i<2; i++) { 29 | inputNumber.add( inFile.nextDouble()); 30 | } 31 | 32 | 33 | return inputNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /v6/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v6/factory/Factory.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.factory; 2 | 3 | public interface Factory { 4 | public Object getInstance(); 5 | } 6 | -------------------------------------------------------------------------------- /v6/factory/ObjectOperationFactory.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.factory; 2 | 3 | import com.company.v6.operation.Addoperation; 4 | import com.company.v6.operation.Divoperation; 5 | import com.company.v6.operation.Muloperation; 6 | import com.company.v6.operation.SubOperation; 7 | 8 | import java.util.List; 9 | 10 | public class ObjectOperationFactory implements Factory{ 11 | private final String str; 12 | private final List inputNumbers; 13 | 14 | public ObjectOperationFactory(List inputNumbers, String str) { 15 | this.inputNumbers = inputNumbers; 16 | this.str = str; 17 | } 18 | 19 | @Override 20 | public Object getInstance() { 21 | Object object = null; 22 | switch(str){ 23 | case "add": 24 | object = new Addoperation(inputNumbers.get(0),inputNumbers.get(1)); 25 | break; 26 | case "sub": 27 | object = new SubOperation(inputNumbers.get(0),inputNumbers.get(1)); 28 | break; 29 | case "mul": 30 | object = new Muloperation(inputNumbers.get(0),inputNumbers.get(1)); 31 | break; 32 | case "div": 33 | object = new Divoperation(inputNumbers.get(0),inputNumbers.get(1)); 34 | break; 35 | default: 36 | System.out.println("Sorry that is not a function of this calculator"); 37 | } 38 | return object; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /v6/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.input; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | 20 | public static interface Inputs { 21 | 22 | String read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v6/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | 7 | class CMDLineInput implements com.company.v6.input.CMDLineInput.Inputs { 8 | 9 | private String args[]; 10 | 11 | public CMDLineInput(String args[]){ 12 | this.args = args; 13 | } 14 | 15 | 16 | @Override 17 | public String read() { 18 | /* String operation = args[0];//read the first argument 19 | return operation;*/ 20 | 21 | return args[0]; //read and return the first argument 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v6/operation/Addoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.operation; 2 | 3 | public class Addoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Addoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a+b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v6/operation/Divoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.operation; 2 | 3 | public class Divoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Divoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | @Override 12 | public double perform() { 13 | 14 | return a/b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v6/operation/Muloperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.operation; 2 | 3 | public class Muloperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Muloperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a*b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v6/operation/Operation.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.operation; 2 | 3 | public interface Operation { 4 | 5 | public double perform(); 6 | } 7 | -------------------------------------------------------------------------------- /v6/operation/SubOperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.operation; 2 | 3 | public class SubOperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public SubOperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a-b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v6/output/ConsoleOutput.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.output; 2 | 3 | public class ConsoleOutput implements Outputs { 4 | @Override 5 | public void show(String text) { 6 | System.out.println(text); 7 | } 8 | } 9 | //factory design pattern -------------------------------------------------------------------------------- /v6/output/Outputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v6.output; 2 | 3 | public interface Outputs { 4 | public void show(String text); 5 | } 6 | -------------------------------------------------------------------------------- /v7/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v7; 10 | 11 | 12 | import com.company.v7.Repository.FileNumberRepository; 13 | import com.company.v7.Repository.NumberRepository; 14 | import com.company.v7.factory.Factory; 15 | import com.company.v7.factory.OperationFactory; 16 | import com.company.v7.input.CMDLineInput; 17 | import com.company.v7.input.Inputs; 18 | import com.company.v7.operation.Operation; 19 | import com.company.v7.output.ConsoleOutput; 20 | import com.company.v7.output.Outputs; 21 | 22 | import java.util.List; 23 | import java.util.Scanner; 24 | 25 | public class Main { 26 | 27 | public static void main(String[] args) { 28 | 29 | Scanner inFile = null; 30 | 31 | Inputs input = new CMDLineInput(args); 32 | String operator = input.read(); 33 | 34 | NumberRepository numberRepository = new FileNumberRepository(); 35 | List inputNumbers = numberRepository.read(); 36 | 37 | 38 | Operation operation = null; 39 | 40 | Factory factoryobject = new OperationFactory(inputNumbers,operator); 41 | operation = (Operation) factoryobject.getInstance(); 42 | 43 | Outputs output = new ConsoleOutput(); 44 | output.show("Answer for "+operator+" is: "+ operation.perform()); 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /v7/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.Repository; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | 9 | public class FileNumberRepository implements NumberRepository { 10 | 11 | 12 | @Override 13 | public List read() { 14 | 15 | List inputNumber = new ArrayList<>(); 16 | List inputNumberstr = null; 17 | 18 | Scanner inFile = null; 19 | 20 | try { 21 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 22 | } catch (FileNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | 27 | 28 | for (int i = 0;i<2; i++) { 29 | inputNumber.add( inFile.nextDouble()); 30 | } 31 | 32 | 33 | return inputNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /v7/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v7/factory/Factory.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.factory; 2 | 3 | public interface Factory { 4 | public Object getInstance(); 5 | } 6 | -------------------------------------------------------------------------------- /v7/factory/OperationFactory.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.factory; 2 | 3 | import com.company.v7.operation.Addoperation; 4 | import com.company.v7.operation.Divoperation; 5 | import com.company.v7.operation.Muloperation; 6 | import com.company.v7.operation.SubOperation; 7 | 8 | import java.util.List; 9 | 10 | public class OperationFactory implements Factory { 11 | private final String str; 12 | private final List inputNumbers; 13 | 14 | public OperationFactory(List inputNumbers, String str) { 15 | this.inputNumbers = inputNumbers; 16 | this.str = str; 17 | } 18 | 19 | @Override 20 | public Object getInstance() { 21 | Object object = null; 22 | switch(str){ 23 | case "add": 24 | object = new Addoperation(inputNumbers.get(0),inputNumbers.get(1)); 25 | break; 26 | case "sub": 27 | object = new SubOperation(inputNumbers.get(0),inputNumbers.get(1)); 28 | break; 29 | case "mul": 30 | object = new Muloperation(inputNumbers.get(0),inputNumbers.get(1)); 31 | break; 32 | case "div": 33 | object = new Divoperation(inputNumbers.get(0),inputNumbers.get(1)); 34 | break; 35 | default: 36 | System.out.println("Sorry that is not a function of this calculator"); 37 | } 38 | return object; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /v7/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.input; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | 20 | public static interface Inputs { 21 | 22 | String read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v7/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | 7 | class CMDLineInput implements com.company.v7.input.CMDLineInput.Inputs { 8 | 9 | private String args[]; 10 | 11 | public CMDLineInput(String args[]){ 12 | this.args = args; 13 | } 14 | 15 | 16 | @Override 17 | public String read() { 18 | /* String operation = args[0];//read the first argument 19 | return operation;*/ 20 | 21 | return args[0]; //read and return the first argument 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v7/operation/Addoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.operation; 2 | 3 | public class Addoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Addoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a+b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v7/operation/Divoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.operation; 2 | 3 | public class Divoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Divoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | @Override 12 | public double perform() { 13 | 14 | return a/b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v7/operation/Muloperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.operation; 2 | 3 | public class Muloperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Muloperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a*b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v7/operation/Operation.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.operation; 2 | 3 | public interface Operation { 4 | 5 | public double perform(); 6 | } 7 | -------------------------------------------------------------------------------- /v7/operation/SubOperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.operation; 2 | 3 | public class SubOperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public SubOperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a-b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v7/output/ConsoleOutput.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.output; 2 | 3 | public class ConsoleOutput implements Outputs { 4 | @Override 5 | public void show(String text) { 6 | System.out.println(text); 7 | } 8 | } 9 | //factory design pattern -------------------------------------------------------------------------------- /v7/output/Outputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v7.output; 2 | 3 | public interface Outputs { 4 | public void show(String text); 5 | } 6 | -------------------------------------------------------------------------------- /v8/Main.java: -------------------------------------------------------------------------------- 1 | /*Authors: Pankajan(SE/2016/032) 2 | Dinindu(SE/2016/033) 3 | Hashika(SE/2016/012) 4 | Udith(SE/2016/047) 5 | Purpose: Assignment of Software Construction 6 | Function : read two numbers from the file and do calculation 7 | */ 8 | 9 | package com.company.v8; 10 | 11 | 12 | import com.company.v8.Repository.DatabaseNumberRepository; 13 | import com.company.v8.Repository.FileNumberRepository; 14 | import com.company.v8.Repository.NumberRepository; 15 | import com.company.v8.factory.Factory; 16 | import com.company.v8.factory.ObjectOperationFactory; 17 | import com.company.v8.input.CMDLineInput; 18 | import com.company.v8.input.Inputs; 19 | import com.company.v8.operation.Operation; 20 | import com.company.v8.output.ConsoleOutput; 21 | import com.company.v8.output.GuiOutput; 22 | import com.company.v8.output.Outputs; 23 | 24 | import java.util.List; 25 | import java.util.Scanner; 26 | 27 | public class Main { 28 | 29 | public static void main(String[] args) { 30 | 31 | Scanner inFile = null; 32 | 33 | Inputs input = new CMDLineInput(args); 34 | String operator = input.read(); 35 | 36 | NumberRepository numberRepository = new DatabaseNumberRepository(); 37 | List inputNumbers = numberRepository.read(); 38 | 39 | 40 | Operation operation = null; 41 | 42 | Factory factoryobject = new ObjectOperationFactory(inputNumbers,operator); 43 | operation = factoryobject.getInstance(); 44 | 45 | Outputs output = new GuiOutput(); 46 | output.show("Answer for "+operator+" is: "+ operation.perform()); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /v8/Repository/DatabaseNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.Repository; 2 | 3 | import java.sql.*; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | public class DatabaseNumberRepository implements NumberRepository { 8 | Connection con; 9 | ResultSet re; 10 | Statement st; 11 | 12 | 13 | @Override 14 | public List read() { 15 | List inputNumber = new ArrayList<>(); 16 | 17 | try { 18 | con= DriverManager.getConnection("jdbc:mysql://localhost/numbers","root",""); 19 | st = con.createStatement(); 20 | re = st.executeQuery("SELECT * FROM number"); 21 | } catch (SQLException e) { 22 | e.printStackTrace(); 23 | } 24 | 25 | try { 26 | while(re.next()) { 27 | inputNumber.add(re.getDouble(1)); 28 | inputNumber.add(re.getDouble(2)); 29 | } 30 | 31 | } catch (SQLException e) { 32 | e.printStackTrace(); 33 | } 34 | 35 | 36 | return inputNumber; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /v8/Repository/FileNumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.Repository; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileReader; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.Scanner; 8 | 9 | public class FileNumberRepository implements NumberRepository { 10 | 11 | 12 | @Override 13 | public List read() { 14 | 15 | List inputNumber = new ArrayList<>(); 16 | List inputNumberstr = null; 17 | 18 | Scanner inFile = null; 19 | 20 | try { 21 | inFile = new Scanner(new FileReader("C:\\Users\\Pankajan\\IdeaProjects\\Software construction\\src\\com\\company\\numbers.txt")); 22 | } catch (FileNotFoundException e) { 23 | e.printStackTrace(); 24 | } 25 | 26 | 27 | 28 | for (int i = 0;i<2; i++) { 29 | inputNumber.add( inFile.nextDouble()); 30 | } 31 | 32 | 33 | return inputNumber; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /v8/Repository/NumberRepository.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.Repository; 2 | 3 | import java.util.List; 4 | 5 | public interface NumberRepository { 6 | 7 | public List read(); 8 | 9 | 10 | } 11 | -------------------------------------------------------------------------------- /v8/factory/Factory.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.factory; 2 | 3 | import com.company.v8.operation.Operation; 4 | 5 | public interface Factory { 6 | public Operation getInstance(); 7 | } 8 | -------------------------------------------------------------------------------- /v8/factory/ObjectOperationFactory.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.factory; 2 | 3 | import com.company.v8.operation.*; 4 | 5 | import java.util.List; 6 | 7 | public class ObjectOperationFactory implements Factory { 8 | private final String str; 9 | private final List inputNumbers; 10 | 11 | public ObjectOperationFactory(List inputNumbers, String str) { 12 | this.inputNumbers = inputNumbers; 13 | this.str = str; 14 | } 15 | 16 | @Override 17 | public Operation getInstance() { 18 | Operation operation = null; 19 | switch(str){ 20 | case "add": 21 | operation = new Addoperation(inputNumbers.get(0),inputNumbers.get(1)); 22 | break; 23 | case "sub": 24 | operation = new SubOperation(inputNumbers.get(0),inputNumbers.get(1)); 25 | break; 26 | case "mul": 27 | operation = new Muloperation(inputNumbers.get(0),inputNumbers.get(1)); 28 | break; 29 | case "div": 30 | operation = new Divoperation(inputNumbers.get(0),inputNumbers.get(1)); 31 | break; 32 | default: 33 | System.out.println("Sorry that is not a function of this calculator"); 34 | } 35 | return operation; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /v8/input/CMDLineInput.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.input; 2 | 3 | public class CMDLineInput implements Inputs { 4 | 5 | private String args[]; 6 | 7 | public CMDLineInput(String args[]){ 8 | this.args = args; 9 | } 10 | 11 | 12 | @Override 13 | public String read() { 14 | /* String operation = args[0];//read the first argument 15 | return operation;*/ 16 | 17 | return args[0]; //read and return the first argument 18 | } 19 | 20 | public static interface Inputs { 21 | 22 | String read(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v8/input/Inputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.input; 2 | 3 | public interface Inputs { 4 | 5 | String read(); 6 | 7 | class CMDLineInput implements com.company.v8.input.CMDLineInput.Inputs { 8 | 9 | private String args[]; 10 | 11 | public CMDLineInput(String args[]){ 12 | this.args = args; 13 | } 14 | 15 | 16 | @Override 17 | public String read() { 18 | /* String operation = args[0];//read the first argument 19 | return operation;*/ 20 | 21 | return args[0]; //read and return the first argument 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /v8/operation/Addoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.operation; 2 | 3 | public class Addoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Addoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a+b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v8/operation/Divoperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.operation; 2 | 3 | public class Divoperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Divoperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | @Override 12 | public double perform() { 13 | 14 | return a/b; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /v8/operation/Muloperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.operation; 2 | 3 | public class Muloperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public Muloperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a*b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v8/operation/Operation.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.operation; 2 | 3 | public interface Operation { 4 | 5 | public double perform(); 6 | } 7 | -------------------------------------------------------------------------------- /v8/operation/SubOperation.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.operation; 2 | 3 | public class SubOperation implements Operation { 4 | private final double a; 5 | private final double b; 6 | 7 | public SubOperation(double a, double b) { 8 | this.a = a; 9 | this.b = b; 10 | } 11 | 12 | @Override 13 | public double perform() { 14 | 15 | return a-b; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /v8/output/ConsoleOutput.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.output; 2 | 3 | public class ConsoleOutput implements Outputs { 4 | @Override 5 | public void show(String text) { 6 | System.out.println(text); 7 | } 8 | } 9 | //factory design pattern -------------------------------------------------------------------------------- /v8/output/GuiOutput.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.output; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | 6 | public class GuiOutput implements Outputs { 7 | @Override 8 | public void show(String str) { 9 | 10 | JOptionPane.showMessageDialog(null,str); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /v8/output/Outputs.java: -------------------------------------------------------------------------------- 1 | package com.company.v8.output; 2 | 3 | public interface Outputs { 4 | public void show(String text); 5 | } 6 | --------------------------------------------------------------------------------