Skip to content

Instantly share code, notes, and snippets.

@alldevic
Created June 3, 2019 13:36
Show Gist options
  • Save alldevic/d7d0ac8e48f8b07ce99c17ba73cc75f6 to your computer and use it in GitHub Desktop.
Save alldevic/d7d0ac8e48f8b07ce99c17ba73cc75f6 to your computer and use it in GitHub Desktop.
using System;
namespace ConsoleApplication9
{
internal class Program
{
public static void Main(string[] args)
{
int x, y;
byte red, green, blue;
try
{
x = ReadInt("Введите координату X:", -1000, 1000);
y = ReadInt("Введите координату Y:", -1000, 1000);
red = (byte) ReadInt("Введите интенсивность красного:", 0, 255);
green = (byte) ReadInt("Введите интенсивность зеленого:", 0, 255);
blue = (byte) ReadInt("Введите интенсивность синего:", 0, 255);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine("Приложение будет закрыто");
Console.ReadKey();
return;
}
var pnt = new Point(x, y, new Color(red, green, blue));
Console.WriteLine(pnt);
}
public static int ReadInt(string message, int min, int max)
{
Console.WriteLine(message);
try
{
var res = Convert.ToInt32(Console.ReadLine());
if (res < min || res > max)
{
throw new ArgumentOutOfRangeException();
}
return res;
}
catch (FormatException)
{
throw new Exception("Введены некорректные данные! Вы ввели не число с плавающей точкой");
}
catch (IndexOutOfRangeException)
{
string exMessage = string.Format("Введены некорректные данные! Введенное число не лежит на [{0}; {1}]",
min, max);
throw new Exception(exMessage);
}
}
}
class Point
{
public int X { get; set; }
public int Y { get; set; }
public Color Color { get; set; }
public Point(int x, int y, Color color)
{
X = x;
Y = y;
Color = color;
}
public override string ToString()
{
return string.Format("({0},{1}):{2}", X, Y, Color);
}
}
class Color
{
public byte Red { get; set; }
public byte Green { get; set; }
public byte Blue { get; set; }
public Color(byte red, byte green, byte blue)
{
Red = red;
Green = green;
Blue = blue;
}
public Color()
{
Red = 0;
Green = 255;
Blue = 0;
}
public override string ToString()
{
return string.Format("({0}:{1}:{2})", Red, Green, Blue);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment