Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package regex;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import static java.lang.System.out;
- public class Ratios {
- private static String line = "HP: 272/272 CP: 204/529 ADRENALINE: 105 ENDORPHINE: 105 BERSERK: 0 None: 0%";
- private static Map<String, String> stats = new HashMap<>();
- private static Map<String, String> ratios = new HashMap<>();
- public static void main(String[] args) {
- out.println(line);
- populateMap();
- ratios();
- }
- private static void populateMap() {
- Pattern pattern = Pattern.compile("(\\w+): +(\\S+)");
- Matcher matcher = pattern.matcher(line);
- while (matcher.find()) {
- stats.put(matcher.group(1), matcher.group(2));
- }
- }
- private static void printMap() {
- for (Map.Entry<String, String> e : stats.entrySet()) {
- String key = e.getKey();
- String val = e.getValue();
- out.println(key + "\t\t" + val);
- }
- }
- private static void ratios() {
- Pattern pattern = Pattern.compile("(\\d+)\\/(\\d+)");
- Matcher matcher;
- String numerator = "", denominator = "";
- for (Map.Entry<String, String> e : stats.entrySet()) {
- out.println(e.getKey());
- matcher = pattern.matcher(e.getValue());
- while (matcher.find()) {
- out.println(matcher.group(2) + "\t" + numerator + "\t" + denominator);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment