Created
March 22, 2011 22:18
-
-
Save RobertoRodrigues/882207 to your computer and use it in GitHub Desktop.
Dojo 22/03/2011 Problema: Conversão de número decimal para Romano
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
import junit.framework.TestCase; | |
public class Dojo extends TestCase { | |
//****metodo para resolver o problema**** | |
String convDecRoman(int decimal) { | |
String roman = ""; | |
if (decimal == 9){ | |
roman = "IX"; | |
} | |
if(decimal <=8 && decimal>=5){ | |
roman += "V"; | |
decimal-=5; | |
} | |
while (decimal<=3 && decimal>0) { | |
roman += "I"; | |
decimal--; | |
} | |
if(decimal == 4){ | |
roman = "IV"; | |
} | |
return roman; | |
} | |
//****testes**** | |
public void teste_1() throws Exception { | |
assertEquals("I",convDecRoman(1)); | |
} | |
public void teste_2() throws Exception { | |
assertEquals("II",convDecRoman(2)); | |
} | |
public void teste_3() throws Exception { | |
assertEquals("III", convDecRoman(3)); | |
} | |
public void teste_4() throws Exception{ | |
assertEquals("IV", convDecRoman(4)); | |
} | |
public void teste_5() throws Exception{ | |
assertEquals("V", convDecRoman(5)); | |
} | |
public void teste_8() throws Exception{ | |
assertEquals("VIII", convDecRoman(8)); | |
} | |
public void teste_9() throws Exception{ | |
assertEquals("IX", convDecRoman(9)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment