Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solución intermedia #28

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
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 amedio/Bowling/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="amedio"/>
<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>
17 changes: 17 additions & 0 deletions amedio/Bowling/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Bowling</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions amedio/Bowling/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#Sat Apr 16 17:02:20 CEST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
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.6
44 changes: 44 additions & 0 deletions amedio/Bowling/amedio/core/Bowling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package core;

public class Bowling {
public static int getPoints(String throwings) {
int result = 0;
int actResult = 0;

for (int i = 0; i < throwings.length(); i++) {
String actValue = String.valueOf(throwings.charAt(i));

if ("-".equals(actValue)) {
actResult = 0;
} else if ("/".equals(actValue)) {
actResult = 10 - actResult
+ valueOfThrow(String.valueOf(throwings.charAt(i + 1)));
} else if ("X".equals(actValue)) {
if (i + 1 >= throwings.length() || i + 2 >= throwings.length())
break;
actResult = 10
+ valueOfThrow(String.valueOf(throwings.charAt(i + 1)))
+ valueOfThrow(String.valueOf(throwings.charAt(i + 2)));
} else {
if (i > 0 && i == (throwings.length() - 1)
&& "/".equals(String.valueOf(throwings.charAt(i - 1))))
break;
actResult = Integer.parseInt(actValue);
}

result += actResult;
}

return result;
}

private static int valueOfThrow(String throwValue) {
int result = 0;
if ("X".equals(throwValue)) {
result = 10;
} else {
result = Integer.parseInt(throwValue);
}
return result;
}
}
30 changes: 30 additions & 0 deletions amedio/Bowling/amedio/core/BowlingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package core;

import junit.framework.Assert;

import org.junit.Test;

public class BowlingTest {
@Test
public void getPointsTest() {
int expected = 0;
int actual = Bowling.getPoints("");
Assert.assertEquals(expected, actual);

expected = 20;
actual = Bowling.getPoints("11111111111111111111");
Assert.assertEquals(expected, actual);

expected = 10;
actual = Bowling.getPoints("1-1-1-1-1-1-1-1-1-1-");
Assert.assertEquals(expected, actual);

expected = 150;
actual = Bowling.getPoints("5/5/5/5/5/5/5/5/5/5/5");
Assert.assertEquals(expected, actual);

expected = 300;
actual = Bowling.getPoints("XXXXXXXXXXXX");
Assert.assertEquals(expected, actual);
}
}