I am confused on how to begin this i have to find a way to read an input file and replace the string and write it to an output file (OUT). The input file (IN) is a deck of cards
I'd recommend test driving a function to do the mapping. The file reading/writing is trivial to look up.
Test driving leads to this:
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 "";
}
}
}
You need to just carry on adding tests to cover all the required functionality.