works well with conditions example, any tips???
disregard isNumber method, it is from one of my previous attempts...
package com.codegym.task.task19.task1924;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/*
Replacing numbers
*/
public class Solution {
public static Map<Integer, String> map = new HashMap<Integer, String>();
static {
map.put(0, "zero");
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
map.put(4, "four");
map.put(5, "five");
map.put(6, "six");
map.put(7, "seven");
map.put(8, "eight");
map.put(9, "nine");
map.put(10, "ten");
map.put(11, "eleven");
map.put(12, "twelve");
}
public static boolean isNumber(char c) {
try {
Integer.parseInt(String.valueOf(c));
return true;
} catch (Exception e) {
return false;
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader fileReader = new BufferedReader(new FileReader(reader.readLine()));
reader.close();
ArrayList<String> lines = new ArrayList<>();
while (fileReader.ready()) {
String line = fileReader.readLine();
lines.add(line);
}
fileReader.close();
for (String line: lines
) {
for (Integer i : map.keySet()
) {
while (line.contains(" " + i + " ") || line.contains(" " + i + ",") || line.contains(" " + i + ".")){
line = line.replace(" " + i + " ", " " + map.get(i) + " ");
line = line.replace(" " + i + ".", " " + map.get(i) + ".");
line = line.replace(" " + i + ",", " " + map.get(i) + ",");
}
}
System.out.println(line);
}
}
}