daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Nov 17th, 2017 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class notifications {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int n = Integer.parseInt(scanner.nextLine());
  7.  
  8.         for (int i = 0; i < n; i++) {
  9.             readAndProcessMessage(scanner);
  10.             System.out.println();
  11.         }
  12.  
  13.  
  14.     }
  15.  
  16.  
  17.     static void showSuccessMessage(String process, String messages) {
  18.         StringBuffer st = new StringBuffer();
  19.         String node = process + "Successfully executed .";
  20.         for (int i = 0; i < node.length(); i++) {
  21.             st.append("=");
  22.         }
  23.         System.out.printf("Successfully executed %s.%n%s%n%s.%n", process, st, messages);
  24.         //System.out.println();
  25.     }
  26.  
  27.     static void showWarningMessage(String messages) {
  28.         StringBuffer st = new StringBuffer();
  29.         String node = messages + "Warning: .";
  30.         for (int i = 0; i < node.length(); i++) {
  31.             st.append("=");
  32.         }
  33.         System.out.printf("Warning: %s.%n%s%n", messages, st);
  34.         //System.out.println();
  35.     }
  36.  
  37.     static void showErrorMessage(String process, String messages, int errorCode) {
  38.         // System.out.println();
  39.         StringBuffer st = new StringBuffer();
  40.         String node = process + "Error: Failed to execute .";
  41.         for (int i = 0; i < node.length(); i++) {
  42.             st.append("=");
  43.         }
  44.         System.out.printf("Error: Failed to execute %s.%n%s%n" +
  45.                 "Reason: %s.%n" +
  46.                 "Error code: %d.%n", process, st, messages, errorCode);
  47.         // System.out.println();
  48.     }
  49.  
  50.     static void readAndProcessMessage(Scanner scanner) {
  51.  
  52.  
  53.         String read = scanner.nextLine().toLowerCase();
  54.         if (read.equals("error")) {
  55.             String process = scanner.nextLine();
  56.             String messages = scanner.nextLine();
  57.             int errorCode = Integer.parseInt(scanner.nextLine());
  58.             showErrorMessage(process, messages, errorCode);
  59.         } else if (read.equals("warning")) {
  60.             String messages = scanner.nextLine();
  61.             showWarningMessage(messages);
  62.         } else if (read.equals("success")) {
  63.             String process = scanner.nextLine();
  64.             String messages = scanner.nextLine();
  65.             showSuccessMessage(process, messages);
  66.         }
  67.  
  68.  
  69.     }
  70.  
  71.  
  72. }
RAW Paste Data
Top