A friend and I have an inside joke; well, not exactly inside if it is based off an existing meme. We would send messages in the 'retarded' form, as the meme 'Retarded Spongebob' does in the example "i WoUlD aPPreCiaTE sOmE fEeDbAcK oN mY CoDE". It takes in an input, loops through the character array formed from the string input, randomises the capitalisation, and the entire array is put back for output. Any improvements that can be suggested?
import java.util.Scanner;
import java.util.concurrent.ThreadLocalRandom;
public class RetardedSpongebobifier {
private char prevChar = 'z';
public static void main(String[] args) {
// Take input of sentence
Scanner scanner = new Scanner(System.in);
System.out.println("Please enter desired sentence to RS.");
// Save input
String input = scanner.nextLine();
// Turn input into a character array
char[] inputArray = input.toCharArray();
RetardedSpongebobifier obj = new RetardedSpongebobifier();
// Create array to hold new array
char[] charArray = new char[input.length()];
// Run through the list of characters, maybe changing them to uppercase or lowercase
for (int i = 0; i < input.length(); i++) {
// Send character for random capitalizing
char adding = obj.randCap(inputArray[i]);
// Add uppercase/lowercase character back into the character array
charArray[i] = adding;
}
// Print array
System.out.print(new String(charArray));
}
private char randCap(char character) {
// Check if character is not any of the blacklisted
if (character == 'i' || character == 'l' || character == ' ' || character == ',' || character == '.') {
prevChar = character;
return character;
}
else {
// Random TRUE/FALSE
boolean isCap = (Math.random() * 100) >= 50;
if (isCap && Character.isLowerCase(prevChar)) {
prevChar = character;
// Return uppercase letter
return Character.toUpperCase(character);
}
else {
prevChar = character;
// Return lowercase letter
return Character.toLowerCase(character);
}
}
}
}