package ua.nure.jfn.task3.converter;

import ua.nure.jfn.task3.Utils;

public class PositionalConverter {

	public static String convert(String s) {
		String[] parts = s.split(":");

		int from = Utils.parseInt(parts[0]);
		int num = Utils.parseInt(parts[1], from);
		int to = Utils.parseInt(parts[2]);

		if (num == 0)
			return "0";

		String result = "";
		for (; num > 0; num /= to) {
			char c = (char) (num % to);

			if (c <= 9) {
				c += '0';
			} else {
				c += 'A' - 10;
			}

			result = c + result;
		}

		return result;
	}

	public static void main(String[] args) {
		String s;

		s = "10:15:16";
		System.out.printf("%s ==> %s%n", s, PositionalConverter.convert(s));
		s = "36:XYZ:2";
		System.out.printf("%s ==> %s%n", s, PositionalConverter.convert(s));
		s = "10:171:36";
		System.out.printf("%s ==> %s%n", s, PositionalConverter.convert(s));
	}

}
