-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hbs
authored and
hbs
committed
Jan 19, 2018
1 parent
3d641da
commit 31a8e0d
Showing
7 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="Test"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>Karakter</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
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.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package no.hib.dat102; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
|
||
/** | ||
* Tester Karakter. | ||
* | ||
* @Ole Olsen | ||
*/ | ||
public class KarakterTest { | ||
|
||
@Test | ||
public void er100enA() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'A', Karakter.beregnKarakter(100)); | ||
} | ||
|
||
@Test | ||
public void er95enA() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'A', Karakter.beregnKarakter(95)); | ||
} | ||
|
||
@Test | ||
public void er90enA() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'A', Karakter.beregnKarakter(90)); | ||
} | ||
|
||
@Test | ||
public void er89enB() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'B', Karakter.beregnKarakter(89)); | ||
} | ||
|
||
@Test | ||
public void er82enB() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'B', Karakter.beregnKarakter(82)); | ||
} | ||
|
||
@Test | ||
public void er80enB() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'B', Karakter.beregnKarakter(80)); | ||
} | ||
|
||
@Test | ||
public void er79enC() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'C', Karakter.beregnKarakter(79)); | ||
} | ||
|
||
@Test | ||
public void er66enC() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'C', Karakter.beregnKarakter(66)); | ||
} | ||
|
||
@Test | ||
public void er60enC() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'C', Karakter.beregnKarakter(60)); | ||
} | ||
|
||
@Test | ||
public void er59enD() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'D', Karakter.beregnKarakter(59)); | ||
} | ||
|
||
@Test | ||
public void er54enD() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'D', Karakter.beregnKarakter(54)); | ||
} | ||
|
||
@Test | ||
public void er50enD() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'D', Karakter.beregnKarakter(50)); | ||
} | ||
|
||
@Test | ||
public void er49enE() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'E', Karakter.beregnKarakter(49)); | ||
} | ||
|
||
@Test | ||
public void er45enE() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'E', Karakter.beregnKarakter(45)); | ||
} | ||
|
||
@Test | ||
public void er40enE() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'E', Karakter.beregnKarakter(40)); | ||
} | ||
|
||
@Test | ||
public void er39enF() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'F', Karakter.beregnKarakter(39)); | ||
} | ||
|
||
@Test | ||
public void er37enF() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'F', Karakter.beregnKarakter(37)); | ||
} | ||
|
||
@Test | ||
public void er0enF() throws FeilKarakterException { | ||
assertEquals("feil karakter", 'F', Karakter.beregnKarakter(0)); | ||
} | ||
|
||
@Test(expected = FeilKarakterException.class) | ||
// Forventer at metoden skal kaste unntaket for at testen skal være riktig. | ||
public void er101ulovlig() throws FeilKarakterException { | ||
Karakter.beregnKarakter(101); | ||
} | ||
|
||
// ... Samme her | ||
@Test(expected = FeilKarakterException.class) | ||
public void erNegativUlovlig() throws FeilKarakterException { | ||
Karakter.beregnKarakter(-1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/no/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package no.hib.dat102; | ||
|
||
/** | ||
* Feilhåndtering for karakter. | ||
* | ||
* @author Ole Olsen | ||
*/ | ||
public class FeilKarakterException extends Exception { | ||
|
||
/** | ||
* Lager et nytt unntak. | ||
* | ||
* @param melding | ||
* melding | ||
*/ | ||
public FeilKarakterException(String melding) { | ||
super(melding); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package no.hib.dat102; | ||
|
||
/** | ||
* Karakter-eksempel. | ||
*/ | ||
public class Karakter { | ||
|
||
// Beregn karakter | ||
// Poengsum mellom 0 and 100 (inklusive) | ||
public static char beregnKarakter(int poeng) throws FeilKarakterException { | ||
char kar; | ||
if (poeng < 0 || poeng > 100) { | ||
throw new FeilKarakterException("ulovlig poeng " + poeng); | ||
} | ||
|
||
if (poeng >= 90) { | ||
kar = 'A'; | ||
} else if (poeng >= 80) { | ||
kar = 'B'; | ||
} else if (poeng >= 60) { | ||
kar = 'C'; | ||
} else if (poeng > 50) {// Logisk feil | ||
kar = 'D'; | ||
} else if (poeng >= 40) { | ||
kar = 'E'; | ||
} else { | ||
kar = 'F'; | ||
} | ||
|
||
return kar; | ||
} | ||
|
||
} |