Skip to content

Instantly share code, notes, and snippets.

@RobertoRodrigues
Created March 22, 2011 22:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertoRodrigues/882207 to your computer and use it in GitHub Desktop.
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
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