-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaySomething.java
More file actions
47 lines (41 loc) · 2.04 KB
/
SaySomething.java
File metadata and controls
47 lines (41 loc) · 2.04 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
// Program: SaySomething
// Description: A cowsay-inspired program that displays the inputted text in a speech bubble.
import java.util.Scanner; // Imports Scanner utility.
public class SaySomething {
public static void main(String[] args) {
Scanner kbd = new Scanner(System.in); // Creates new scanner.
// Startup information
System.out.println("SaySomething");
System.out.println("(0) 2024 CommonPolarity. No rights reserved.");
System.out.println("This program is licensed under the MIT License.");
// Main program
while (true) {
System.out.print("What do you want me to say?: ");
String say = kbd.nextLine();
if (say.equals("!exit")) {
System.out.println("Are you sure you want to exit? (y/n)");
String exitconfirm = kbd.next();
if (exitconfirm.equalsIgnoreCase("y")) {
break; // Exits program.
} else if (exitconfirm.equalsIgnoreCase("n")) {
continue; // Continues SaySomething.
}
} else {
int boxlength = say.length();
if (boxlength <= 2) {
System.out.println(" " + "_".repeat(boxlength));
System.out.println("/" + " ".repeat(boxlength) + "\\");
System.out.println("|" + say + "|");
System.out.println(" " + "\\/");
} else {
System.out.println(" " + "_".repeat(boxlength)); // Adds a blankspace & repeats "_" with variable boxlength.
System.out.println("/" + " ".repeat(boxlength) + "\\");
System.out.println("|" + say + "|");
System.out.println("\\" + "_".repeat(boxlength - 3) + " /"); // Repeats "_" via boxlength except subtracted by 3.
System.out.println(" ".repeat(boxlength - 2) + "\\/");
}
}
}
kbd.close();
}
}