Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.util.List;
  4. import java.util.Scanner;
  5. import java.util.stream.Collectors;
  6.  
  7. public class EmailValidator {
  8. public static void main(String[] args) {
  9.  
  10. Scanner scanner = new Scanner(System.in);
  11.  
  12. String email = scanner.nextLine();
  13.  
  14. List<String> input = Arrays.stream(email.split("")).collect(Collectors.toList());
  15.  
  16. while (true){
  17.  
  18. String[] cmd = scanner.nextLine().split(" ");
  19.  
  20. if (cmd[0].equals("Complete")){
  21. break;
  22. }
  23.  
  24. if (cmd[0].equals("Make")){
  25.  
  26. if (cmd[1].equals("Upper")){
  27. System.out.println(email.toUpperCase());
  28.  
  29. for (int i = 0; i <input.size() ; i++) {
  30.  
  31. String symbol = input.get(i);
  32.  
  33. input.set(i,symbol.toUpperCase());
  34. }
  35. }
  36.  
  37. else if (cmd[1].equals("Lower")){
  38. System.out.println(email.toLowerCase());
  39.  
  40. for (int i = 0; i <input.size() ; i++) {
  41.  
  42. String symbol = input.get(i);
  43.  
  44. input.set(i,symbol.toLowerCase());
  45. }
  46. }
  47. }
  48. else if (cmd[0].equals("GetDomain")){
  49.  
  50. int count = Integer.parseInt(cmd[1]);
  51.  
  52. System.out.println(input.subList((input.size()-count),input.size()).toString()
  53. .replace("[","")
  54. .replace("]","")
  55. .replace(",","")
  56. .replace(" ",""));
  57. }
  58.  
  59. else if (cmd[0].equals("GetUsername")){
  60.  
  61. int index = input.indexOf("@");
  62.  
  63. if (index>=0) {
  64. System.out.println(email.substring(0,index));
  65. }
  66. else {
  67. System.out.printf("The email %s doesn't contain the @ symbol.",email);
  68. System.out.println();
  69. }
  70. }
  71. else if (cmd[0].equals("Replace")){
  72.  
  73. for (int i = 0; i <input.size() ; i++) {
  74.  
  75. if (input.get(i).equals(cmd[1])){
  76. input.set(i,"-");
  77. }
  78.  
  79. email = input.toString()
  80. .replace("[","")
  81. .replace("]","")
  82. .replace(",","")
  83. .replace(" ","");
  84. }
  85. System.out.println(email);
  86. }
  87. else if (cmd[0].equals("Encrypt")){
  88.  
  89. for (String s : input) {
  90.  
  91. System.out.print(((int) s.charAt(0))+" ");
  92. }
  93.  
  94. System.out.println();
  95. }
  96.  
  97. }
  98.  
  99. }
  100.  
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement