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
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="tests"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//src/defaultpackage/StringCalculatorProduct.java=Cp1252
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=1.6
Binary file added bin/defaultpackage/StringCalculator.class
Binary file not shown.
Binary file added bin/defaultpackage/StringCalculatorProduct.class
Binary file not shown.
Binary file added bin/defaultpackage/calculatorTester.class
Binary file not shown.
24 changes: 24 additions & 0 deletions src/defaultpackage/StringCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package defaultpackage;
import java.util.Scanner;
import java.lang.StringBuilder;

public class StringCalculator {
private StringCalculatorProduct stringCalculatorProduct = new StringCalculatorProduct();
Scanner getString=new Scanner(System.in);
StringBuilder deleter= new StringBuilder();
public String addNumbers()
{
String theStringForTheCalculator=getString.nextLine();
System.out.println("The string added: "+theStringForTheCalculator);
return stringCalculatorProduct.calculatorMethod(theStringForTheCalculator, this.deleter, this);
}
public boolean unknownAmountOfNumbers(String stringFromCalc){
if(stringFromCalc.length()>2||stringFromCalc.length()<0)
{
return false;
}
else{
return true;
}
}
}
82 changes: 82 additions & 0 deletions src/defaultpackage/StringCalculatorProduct.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package defaultpackage;


public class StringCalculatorProduct {
//This is the God Class that the JDeodorant structured by itself.
//I was not able to understand what the JDeodorant is suggesting and I had to see what it does.
private int a;
private int b = 0;
private char[] numberArray;
private String numbers;

public int calculateSum() {
int sum = 0;
sum = a + b;
return sum;
}

public void setB() {
//This is the first change I created. From Long Method feature of the JDeodorant it came up there is this too long method in if-clause.
b = Integer.parseInt(String.valueOf(numberArray[1]));
System.out.println("b set to:" + b);
}

public String calculatorMethod(String numbersSend,
StringBuilder thisDeleter, StringCalculator stringCalculator) {
numbers = numbersSend;
numberArray = numbers.toCharArray();
if (numberArray.length > 2) {
for (int j = 0; j < numberArray.length; j++) {
if (numberArray[j] == '\\' && numberArray[j + 1] == 'n') {
numbers = new String(numberArray);
thisDeleter.append(numbers);
thisDeleter.deleteCharAt(j);
thisDeleter.deleteCharAt(j);
numberArray = thisDeleter.toString().toCharArray();
System.out.println("Numberarray in for after all: "
+ numberArray[0] + numberArray[1]);
System.out.println("Numberarray length: "
+ numberArray.length);
numbers = new String(numberArray);
}
}
}
System.out.println("The char array created.");
int theSum = theSum(stringCalculator);
System.out.println("Sum set minus one and defined.");
String stringBack = null;
System.out.println("stringBack defined and set null.");
if (!stringCalculator.unknownAmountOfNumbers(numbers))
unknownNumb();
else {
System.out.println("a set to something.");
System.out.println("A is:" + a + "\n And B is: " + b);
System.out.println("The sum is: " + theSum);
stringBack = Integer.toString(theSum);
System.out.println("stringBack is: " + stringBack);
}
return stringBack;
}

public int theSum(StringCalculator stringCalculator)
throws java.lang.NumberFormatException {
int theSum = -1;
if (!stringCalculator.unknownAmountOfNumbers(numbers)) {
} else {
a = Integer.parseInt(String.valueOf(numberArray[0]));
if (numberArray.length > 1)
setB();
theSum = calculateSum();
}
return theSum;
}

public void unknownNumb() {
System.out.println("Unknown amount of numbers.");
unknownNumberHandler(numbers);
}

public void unknownNumberHandler(String unknownNumbers) {
unknownNumbers = null;
}
}
25 changes: 25 additions & 0 deletions tests/defaultpackage/calculatorTester.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package defaultpackage;

import static org.junit.Assert.*;

import org.junit.Test;
import java.util.Scanner;

public class calculatorTester {

@Test
public void test() {
//fail("Not yet implemented");
}
@Test
public void insertString(){
StringCalculator calc = new StringCalculator();
String stringReturned = calc.addNumbers();
System.out.println("String returned to test: "+stringReturned);
if(stringReturned==null)
{
fail("No sum executed.");
}
}

}