public class Chipper {
public static void main(String[] args) {
int range = (50 – 1) + 1; // 50 is max value 1 is min value
int rand1 = (int) (Math.random() * range) + 1;// 1.a)gives a random
// number between 1 and
// 50
int rand2 = (int) (Math.random() * range) + 1;
int rand3 = (int) (Math.random() * range) + 1;
String msg1 = null;// 1.b) all strings in three input variables
String msg2 = null;
String msg3 = null;
Scanner in = new Scanner(System.in);
System.out.println(“Enter a message with ” + rand1 + ” character or less”);
msg1 = in.nextLine();
if (msg1.length() > rand1) {
System.out.println(“Oops! youe message is more than ” + rand1 + ” characters! it has been truncated to:”);
msg1 = msg1.substring(0, rand1);// 1.c) truncate string if
// length is more than random
// variable
System.out.println(msg1);
}
System.out.println(“Enter a message with ” + rand2 + ” character or less”);
msg2 = in.nextLine();
if (msg2.length() > rand2) {
System.out.println(“Oops! youe message is more than ” + rand2 + ” characters! it has been truncated to:”);
msg2 = msg2.substring(0, rand2);
System.out.println(msg2);
}
System.out.println(“Enter a message with ” + rand3 + ” character or less”);
msg3 = in.nextLine();
if (msg3.length() > rand3) {
System.out.println(“Oops! youe message is more than ” + rand3 + ” characters! it has been truncated to:”);
msg3 = msg3.substring(0, rand3);
System.out.println(msg3);
}
System.out.println(“Here is message1: ” + msg1);
System.out.println(“Here is message2: ” + msg2);
System.out.println(“Here is message3: ” + msg3);
String msgAll = msg1.concat(msg2).concat(msg3);// 2.Concatenate all
// string in one
System.out.println(“Here are your three messages combined: “);
System.out.println(msgAll);
System.out.println(“Here are your messages in all uppercase: “);
System.out.println(msgAll.toUpperCase());
System.out.println(“Here are your messages in all lowercase: “);
System.out.println(msgAll.toLowerCase());
int msg1Length = msg1.length();// 3.keeps the track of lengths of all
// three messages
int msg2Length = msg2.length();
int msg3Length = msg3.length();
// 4. a) count the total no of characters in string b) vowel count
// c)space count
int charCount = 0;
int spaceCount = 0;
int vowelCount = 0;
char temp;
for (int i = 0; i < msgAll.length(); i++) {
temp = msgAll.charAt(i);
if (temp != ‘ ‘)
charCount++;// counts character in string
if (temp == ‘ ‘)
spaceCount++;// count space in string
if ((temp == ‘a’) || (temp == ‘e’) || (temp == ‘i’) || (temp == ‘o’) || (temp == ‘u’))
vowelCount++;// counts vowels in string
}
System.out.println(“The count of character in all your messages: ” + charCount);
System.out.println(“The numbers of vowels in all your messages: ” + vowelCount);
System.out.println(“The number of spaces in all your messages: ” + spaceCount);
String backwardString = “”;
for (int i = msgAll.length() – 1; i >= 0; i–) {
backwardString = backwardString + msgAll.charAt(i);// 5. backward
// the string
// msgAll
}
System.out.println(“Here is your message backwards: ” + backwardString);
System.out.println(“Here is your message vertical: “);
for (int i = 0; i < msgAll.length(); i++) {
System.out.println(msgAll.toUpperCase().charAt(i));
}
}
}
output:

