Задача: известия
Задача: известия от книгата "Основи на програмирането" (с Java)
https://java-book.softuni.bg/chapter-10-methods.html
моля някои ако има решението нека сподели
https://java-book.softuni.bg/chapter-10-methods.html
моля някои ако има решението нека сподели
Решение:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notifications
{
class Program
{
static void Main(string[] args)
{
var n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
ReadAndProcessMessage();
Console.WriteLine();
}
}
static void ReadAndProcessMessage()
{
string messageType = Console.ReadLine();
if (messageType == "success")
{
string operation = Console.ReadLine();
string message = Console.ReadLine();
ShowSuccessMessage(operation, message);
}
else if (messageType == "warning")
{
string warningmessage = Console.ReadLine();
ShowWarningMessage(warningmessage);
}
else if (messageType == "error")
{
string operation = Console.ReadLine();
string errormessage = Console.ReadLine();
int errorCode = int.Parse(Console.ReadLine());
ShowErrorMessage(operation, errormessage, errorCode);
}
}
static void ShowSuccessMessage(string operation, string message)
{
string head = "Successfully executed " + operation + ".";
Console.WriteLine(head);
Console.WriteLine(new string('=', head.Length));
Console.WriteLine("{0}.", message);
}
static void ShowWarningMessage(string warningmessage)
{
string head = "Warning: " + warningmessage + ".";
Console.WriteLine(head);
Console.WriteLine(new string('=', head.Length));
}
static void ShowErrorMessage(string operation, string errormessage, int errorCode)
{
string head = "Error: Failed to execute " + operation + ".";
Console.WriteLine(head);
Console.WriteLine(new string('=', head.Length));
Console.WriteLine("Reason: {0}.", errormessage);
Console.WriteLine("Error code: {0}.", errorCode);
}
}
}