题目
这是大城市的奖励时间!胖子正在期待摩擦他们的爪子......但是谁会赚到最多钱?
构建一个包含两个参数(工资,奖金)的函数。工资将是一个整数,并加上一个布尔值。
如果奖金是真的,薪水应该乘以10.如果奖金是假的,胖子没有赚到足够的钱,必须只收到他说的工资。
返回个人将收到的总数字作为前缀为“£”(= "\u00A3"
,JS和Java)或“$”(C#,C ++,Ruby,Clojure,Elixir,PHP和Python,Haskell)的字符串。
测试用例:
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
public class BonusTimeTest {
@Test
public void basicTests() {
boolean wellConfigured=unicodeTest();
assertEquals((wellConfigured?"£":"\u00A3")+"100000",Kata.bonusTime(10000, true));
assertEquals((wellConfigured?"£":"\u00A3")+"250000",Kata.bonusTime(25000, true));
assertEquals((wellConfigured?"£":"\u00A3")+"10000",Kata.bonusTime(10000, false));
assertEquals((wellConfigured?"£":"\u00A3")+"60000",Kata.bonusTime(60000, false));
assertEquals((wellConfigured?"£":"\u00A3")+"20",Kata.bonusTime(2, true));
assertEquals((wellConfigured?"£":"\u00A3")+"78",Kata.bonusTime(78, false));
assertEquals((wellConfigured?"£":"\u00A3")+"678900",Kata.bonusTime(67890, true));
}
public boolean unicodeTest(){
System.out.println("\u00A3 == £:"+"\u00A3".equalsIgnoreCase("£"));
System.out.println("if previous result was false or had ? symbol then perhaps you need to escape unicode due to misconfiguration");
return "\u00A3".equalsIgnoreCase("£");
}
}
解题
My
public class Kata{
public static String bonusTime(final int salary, final boolean bonus) {
return "£"+String.valueOf(bonus ? salary*10 : salary);
}
}
Other
public class Kata{
public static String bonusTime(final int salary, final boolean bonus) {
return "\u00A3" + (bonus ? 10 : 1) * salary;
}
}
后记
看到别人的代码就知道我不懂出题者呀。