Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.5 kB
4
Indexable
Never
    import java.math.BigInteger;

    public class Main {
        public static void main(String args[]) {
            String countryCode = args[0];
            String bankCode = args[1];
            String accountNumber = args[2];

            char[] countryCodeArray = countryCode.toCharArray();
            char[] accountNumberArray = accountNumber.toCharArray();
            int countryCodeNum1 = (int) countryCodeArray[0] - 64 + 9;
            int countryCodeNum2 = (int) countryCodeArray[1] - 64 + 9;
            String countryCodeNum = String.valueOf(countryCodeNum1) +
                    String.valueOf(countryCodeNum2) + "00";

            if (accountNumberArray.length < 10) {
                for (int i = 0; i < (10 - accountNumberArray.length); i++)
                    accountNumber = '0' + accountNumber;
            }

            long longCountryCode = Long.valueOf(countryCodeNum);
            long longBankcode = Long.valueOf(bankCode);
            long longAccountNum = Long.valueOf(accountNumber);

            BigInteger bankCodeHelp = new BigInteger("10000000000000000");
            BigInteger accountNumHelp = new BigInteger("1000000");
            BigInteger BigIntegerBankCode = BigInteger.valueOf((longBankcode)).multiply(bankCodeHelp);
            BigInteger BigIntegerAccountNum = BigInteger.valueOf((longAccountNum)).multiply(accountNumHelp);
            BigInteger BigIntegerCountryCode = BigInteger.valueOf((longCountryCode));
            BigInteger BigCode = BigIntegerBankCode.add(BigIntegerAccountNum.add(BigIntegerCountryCode));
            BigInteger valueModulo = new BigInteger("97");
            BigInteger modulo = BigCode.mod(valueModulo);
            BigInteger sub = new BigInteger("98");
            BigInteger bigCheckSum = sub.subtract(modulo);

            String stringCheckSum = bigCheckSum.toString();
            char[] arrayCheckSum = stringCheckSum.toCharArray();

            if (arrayCheckSum.length < 2)
                stringCheckSum = "0" + stringCheckSum;

            String connection = countryCode + stringCheckSum + bankCode + accountNumber;
            char[] arrayConnection = connection.toCharArray();
            String lastConnnection = "";

            for (int i = 0, j = i + 1; i < arrayConnection.length; i++) {

                lastConnnection += arrayConnection[i];
                if (j % 4 == 0)
                    lastConnnection += " ";
                j++;

            }
            System.out.println(lastConnnection);

        }
    }