-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageConverter.java
More file actions
69 lines (63 loc) · 1.83 KB
/
MessageConverter.java
File metadata and controls
69 lines (63 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import java.util.Scanner;
/**
* Takes an input message, modifies message then outputs the modified message.
*
* @author Adam Bostwick
* @version 9/9/19
*/
public class MessageConverter
{
/** @param args Command line arguments (not used). */
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
String message = "";
int outputType = 0;
String result = "";
System.out.print("Type in a message and press enter:\n\t> ");
message = userInput.nextLine();
System.out.print("\nOutput types:"
+ "\n\t0: As is "
+ "\n\t1: Trimmed"
+ "\n\t2: lower case"
+ "\n\t3: UPPER CASE"
+ "\n\t4: v_w_ls r_pl_c_d"
+ "\n\t5: Without first and last character"
+ "\nEnter your choice: ");
outputType = Integer.parseInt(userInput.nextLine());
if (outputType == 0) //as is
{
result = message;
}
else if (outputType == 1) //trimmed
{
result = message.trim();
}
else if (outputType == 2) //lower case
{
result = message.toLowerCase();
}
else if (outputType == 3) //upper case
{
result = message.toUpperCase();
}
else if (outputType == 4) //vowels replaces
{
result = message.replace('a', '_');
result = result.replace('e', '_');
result = result.replace('i', '_');
result = result.replace('o', '_');
result = result.replace('u', '_');
}
else if (outputType == 5) //without 1st and last character
{
result = message.substring(1, message.length() - 1);
}
else // invalid input
{
result = "Error: Invalid choice input.";
}
System.out.print("\n" + result);
userInput.close();
}
}