Advertisement
aggressiveviking

Untitled

Mar 8th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.22 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _13.Notifications
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var n = int.Parse(Console.ReadLine());
  10.            
  11.             for (int i = 0; i < n; i++)
  12.             {
  13.                 ReadAndProcessMessage();
  14.                 Console.WriteLine();
  15.             }
  16.         }
  17.         static void ReadAndProcessMessage()
  18.         {
  19.             string messageType = Console.ReadLine();
  20.            
  21.             if (messageType == "success")
  22.             {
  23.                 string operation = Console.ReadLine();
  24.                 string message = Console.ReadLine();
  25.  
  26.                 ShowSuccessMessage(operation, message);
  27.  
  28.             }
  29.             else if (messageType == "warning")
  30.             {
  31.                 string warningmessage = Console.ReadLine();
  32.  
  33.                 ShowWarningMessage(warningmessage);
  34.             }
  35.             else if (messageType == "error")
  36.             {
  37.                 string operation = Console.ReadLine();
  38.                 string errormessage = Console.ReadLine();
  39.                 int errorCode = int.Parse(Console.ReadLine());
  40.  
  41.                 ShowErrorMessage(operation, errormessage, errorCode);
  42.             }
  43.         }
  44.         static void ShowSuccessMessage(string operation, string message)
  45.         {
  46.             string head = "Successfully executed " + operation + ".";
  47.  
  48.             Console.WriteLine(head);
  49.             Console.WriteLine(new string('=', head.Length));
  50.             Console.WriteLine("{0}.", message);
  51.         }
  52.         static void ShowWarningMessage(string warningmessage)
  53.         {
  54.             string head = "Warning: " + warningmessage + ".";
  55.            
  56.             Console.WriteLine(head);
  57.             Console.WriteLine(new string('=', head.Length));
  58.         }
  59.         static void ShowErrorMessage(string operation, string errormessage, int errorCode)
  60.         {
  61.             string head = "Error: Failed to execute " + operation + ".";
  62.            
  63.             Console.WriteLine(head);
  64.             Console.WriteLine(new string('=', head.Length));
  65.             Console.WriteLine("Reason: {0}.", errormessage);
  66.             Console.WriteLine("Error code: {0}.", errorCode);
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement