Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.32 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Notifications5 {
  5.     public static void main(String[] args) {
  6.  
  7.         readAndProcessMessage();
  8.     }
  9.     private static void showSuccessMessage(String operation, String message) {
  10.         System.out.printf("Successfully executed %s.%n", operation);
  11.         char[] row = new char[operation.length()];
  12.         Arrays.fill(row, '=');
  13.         System.out.println(row);
  14.         System.out.printf("%s.%n", message);
  15.         System.out.println();
  16.     }
  17.     private static void showWarningMessage(String message) {
  18.         message = "Warning: " + message + '.';
  19.         System.out.println(message);
  20.         char[] row = new char[message.length()];
  21.         Arrays.fill(row, '=');
  22.         System.out.println(row);
  23.         System.out.println();
  24.     }
  25.     private static void showErrorMessage(String operation, String message, int errorCode) {
  26.         System.out.printf("Failed to execute %s.%n", operation);
  27.         char[] row = new char[operation.length()];
  28.         Arrays.fill(row, '=');
  29.         System.out.println(row);
  30.         System.out.printf("Reason: %s.%n", message);
  31.         System.out.printf("Error code: %d.%n", errorCode);
  32.         System.out.println();
  33.     }
  34.     private static void readAndProcessMessage() {
  35.         Scanner scanner = new Scanner(System.in);
  36.  
  37.         int messagesNumber = Integer.parseInt(scanner.nextLine());
  38.  
  39.         for (int i = 0; i < messagesNumber; i++) {
  40.             String messageType = scanner.nextLine();
  41.  
  42.             switch (messageType) {
  43.                 case "success":
  44.                     String operation = scanner.nextLine();
  45.                     String message = scanner.nextLine();
  46.                     showSuccessMessage(operation, message);
  47.                     break;
  48.                 case "warning":
  49.                     message = scanner.nextLine();
  50.                     showWarningMessage(message);
  51.                     break;
  52.                 case "error":
  53.                     operation = scanner.nextLine();
  54.                     message = scanner.nextLine();
  55.                     int errorCode = Integer.parseInt(scanner.nextLine());
  56.                     showErrorMessage(operation, message, errorCode);
  57.                     break;
  58.                 default:
  59.                     break;
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement