12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Avalonia.Controls;
- using Avalonia.Interactivity;
- using System;
- namespace _01_02_MDK
- {
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- }
- enum Triangles
- {
- Isosceles, //Ðàâíîáåäðåííûé
- Equilateral, //Ðàâíîñòîðîííèé
- Versatile, //Ðàçíîñòîðîííèé
- NotExist //Íå ñóùåñòâóåò
- }
- private void pressedButton_Click(object sender, RoutedEventArgs e)
- {
- try {
- var a = Convert.ToInt32(firstSide.Text);
- var b = Convert.ToInt32(secondSide.Text);
- var c = Convert.ToInt32(thirdSide.Text);
- var triangleType = DetermineTypeOfTriangle(a, b, c);
- typeOfTriangle.Text = FromEnumToString(triangleType);
- }
- catch (FormatException)
- {
- typeOfTriangle.Text = "Ââåä¸ííûå çíà÷åíèÿ íåêîððåêòíû. Ïîïðîáóéòå åù¸ ðàç!";
- }
- catch (Exception ex) {
- typeOfTriangle.Text= ex.Message;
- }
- }
- static string FromEnumToString(Triangles triangle)
- {
- return new[] { "Ðàâíîáåäðåííûé", "Ðàâíîñòîðîííèé", "Ðàçíîñòîðîííèé", "Íå ñóùåñòâóåò" }[(int)triangle];
- }
- static Triangles DetermineTypeOfTriangle(int a, int b, int c)
- {
- if (a + b > c && a + c > b && b + c > a)
- {
- if (a == b || b == c || c == a)
- {
- if (a == b && b == c)
- return Triangles.Equilateral;
- return Triangles.Isosceles;
- }
- return Triangles.Versatile;
- }
- return Triangles.NotExist;
- }
- }
- }
|