我很困惑如何开始这个我必须找到一种方法来读取输入文件并替换字符串并将其写入输出文件(OUT)。输入文件(IN)是一副纸牌
答案 0 :(得分:0)
我建议测试驱动一个函数来进行映射。文件读/写很容易查找。
试驾导致:
public class CardsTests {
@Test
public void TwoOfHearts() {
Assert.assertEquals("Two of hearts (value = 2)", Card.fromString("2-H"));
}
@Test
public void ThreeOfHearts() {
Assert.assertEquals("Three of hearts (value = 3)", Card.fromString("3-H"));
}
@Test
public void ThreeOfSpades() {
Assert.assertEquals("Three of spades (value = 3)", Card.fromString("3-S"));
}
}
public class Card {
public static String fromString(String string) {
char value = string.charAt(0);
String textValue = valueToText(value);
String suit = getSuit(string.charAt(2));
return String.format("%s of %s (value = %c)", textValue, suit,
value);
}
private static String getSuit(char value) {
switch (value) {
case 'H':
return "hearts";
case 'S':
return "spades";
default:
return "";
}
}
private static String valueToText(char value) {
switch (value) {
case '2':
return "Two";
case '3':
return "Three";
default:
return "";
}
}
}
您需要继续添加测试以涵盖所有必需的功能。