Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace PlaneLib
  8. {
  9.     class Circle : PlaneFigure
  10.     {
  11.         static Random rnd = new Random();
  12.  
  13.         private string name;
  14.  
  15.         public string Name
  16.         {
  17.             get { return name; }
  18.         }
  19.  
  20.         private double radius;
  21.  
  22.         public double Radius
  23.         {
  24.             get { return radius; }
  25.             set
  26.             {
  27.                 if (value <= 0)
  28.                 {
  29.                     throw new PlaneFigureException("the circle's radius is non-positive");
  30.                 }
  31.                 else
  32.                 {
  33.                     radius = value;
  34.                 }
  35.             }
  36.         }
  37.  
  38.  
  39.         public Circle(string name, double _radius) : base(name)
  40.         {
  41.             this.Radius = _radius;
  42.             this.name = name;
  43.         }
  44.  
  45.         public override double Area
  46.         {
  47.             get
  48.             {
  49.                 return Math.PI * this.Radius * this.Radius;
  50.             }
  51.         }
  52.  
  53.         public override void ChangePlaneFigure()
  54.         {
  55.             double curr = -1;
  56.             while (curr <= 0)
  57.             {
  58.                 curr = rnd.Next(-2, 6) + rnd.NextDouble();
  59.                 this.Radius = curr;
  60.             }
  61.         }
  62.  
  63.         public override string ToString()
  64.         {
  65.             return base.ToString() + $"Circle with radius: {Radius} cm";
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement