From c0f5a11fc8489fce68af97d3a1979b4f14385e90 Mon Sep 17 00:00:00 2001 From: Saku Ruohola Date: Mon, 1 Oct 2018 18:12:28 +0300 Subject: [PATCH] Assignment Finished --- bin/StringCalculator.class | Bin 405 -> 1514 bytes src/StringCalculator.java | 51 +++++++++++++++++++++++++++-- src/StringCalculatorException.java | 2 +- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/bin/StringCalculator.class b/bin/StringCalculator.class index a937b0c43633d36f133837cd90ddd10fb14ac782..ddf6e4bb82f9dca522c04c4a7315365051f876cb 100644 GIT binary patch literal 1514 zcmZvcOK%cU6vzJ;28Iq(TcDuWN`03CrC95e)>o~Dq_&Hi8f{FR(y@-xfeeGu#HC-t z$3{19TSL)l7KQ(Uo|xZ(W4`Tut49O zWt;P@^%c{(ZmiTyf%sg#YSfkt$CCSwQE~5CO?kF8Z<&#e)m4FHcJ5zx->W=Y5zuBI zRn3NL)$OK=xIlVqgzmY90i;wUH|g-bb?n9-0o7{Gt~cDro|;=41or9}#1OMI8#T+V z*o_u7r*=YFu1Nokj$!Ns5;9ChD;b1!$4fIgn|bFFX}^TK>*@DMFmgVW(J z+I;>463+Egq6X-37)LmV zaS=x`!W=19AWNIVNMNkcZ={8aoJgyIpY#jJ-sfFet9SI0B1@jcI7N{$NoC?APAqt83RLrB>|Iw)#)~t^I71}eMAdp6MrNv~pB^7s1mY~&7oi#KHl4CFUnU{`)4{2CF3^$!K7|EqVL(ZQHe z)}t3W#F6)?a-MylOErLVWZ`$nnCEeUvE%&tD_KdtSpP2wS#= 0) { + testOfValue(numberArray[i]); + sum += numberArray[i]; + } else throw new StringCalculatorException(); + } + } + + + return sum; + } + + private int[] splitInput(String numbersToSplit) { + String [] numbers; + int[] sum = new int[3]; + numbers = numbersToSplit.split("[,|\n]"); + if(testOfLength(numbers)) { + for(int i = 0; i < numbers.length; i++) { + sum[i] = Integer.parseInt(numbers[i]); + } + } + + return sum; } + + private boolean testOfLength(String[] testString) { + boolean test; + if(testString.length >= 0 && testString.length < 3) { + test = true; + } else test = false; + return test; + } + + private boolean testOfValue(int value) throws StringCalculatorException { + boolean test; + if(value < 0) { + test = true; + } else throw new StringCalculatorException(); + return test; + } + } diff --git a/src/StringCalculatorException.java b/src/StringCalculatorException.java index da71147..9f37ce4 100644 --- a/src/StringCalculatorException.java +++ b/src/StringCalculatorException.java @@ -1,4 +1,4 @@ public class StringCalculatorException extends Exception { - +// I expect that this doesn't need to edited as there was only talk of throwing it }