Another Caesar Cipher implementation..

..in Java. As Usual..

Directory Layout

Encrypter.java
public interface Encrypter {
 
    String encrypt(final String claerText);
    void setKey(int key);
}

CaesarCipherEncrypter.java
public class CaesarCipherEncrypter implements Encrypter {
 
    private int key;
 
    @Override
    public final String encrypt(final String clearText) {
        final StringBuilder stringBuilder = new StringBuilder();
        for (Character clearCharacter : clearText.toCharArray()) {
            clearCharacter = Character.toUpperCase(clearCharacter);
 
            if (clearCharacter < 'A' || clearCharacter > 'Z') {
                stringBuilder.append(" ");
                continue;
            }
 
            int encryptedChar = clearCharacter + key;
            if (encryptedChar < 'A') {
                encryptedChar = encryptedChar + 'Z' - 'A' + 1;
            }
 
            if (encryptedChar > 'Z') {
                encryptedChar = encryptedChar + 'A' - 'Z' - 1;
            }
 
            stringBuilder.append((char) (encryptedChar));
        }
        return stringBuilder.toString();
    }
 
    @Override
    public void setKey(int key) {
        this.key = key;
    }
}

TestClass.java
public final class TestClass {
 
    public static void main(final String[] args) {
        final Encrypter encrypter = new CaesarCipherEncrypter();
        encrypter.setKey(Integer.valueOf(args[0]));
 
        final StringBuilder stringBuilder = new StringBuilder();
        for (int i = 1; i < args.length; i++) {
            stringBuilder.append(args[i]);
            stringBuilder.append(" ");
        }
 
        final String encryptedText = encrypter.encrypt(stringBuilder.toString());
        System.out.println(encryptedText);
    }
}

Compile

Sample Run

Learn Cryptography tells this implementation is ok!