Advertisement
d_brezoev

zz

May 25th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1. namespace SimplifyExpression
  2. {
  3.     /*Refactor the following code to use proper variable naming and simplified expressions:*/
  4.     using System;
  5.  
  6.     public class Rectangle
  7.     {
  8.         private double width, height;
  9.  
  10.         public Rectangle(double width, double height)
  11.         {
  12.             this.Width = width;
  13.             this.Height = height;
  14.         }
  15.  
  16.         public double Width
  17.         {
  18.             get
  19.             {
  20.                 return this.width;
  21.             }
  22.  
  23.             private set
  24.             {
  25.                 if (value < 0)
  26.                 {
  27.                     throw new ArgumentOutOfRangeException("Width cannot be less than zero.");
  28.                 }
  29.  
  30.                 this.width = value;
  31.             }
  32.         }
  33.  
  34.         public double Height
  35.         {
  36.             get
  37.             {
  38.                 return this.height;
  39.             }
  40.  
  41.             private set
  42.             {
  43.                 if (value < 0)
  44.                 {
  45.                     throw new ArgumentOutOfRangeException("Height cannot be less than zero.");
  46.                 }
  47.  
  48.                 this.height = value;
  49.             }
  50.         }        
  51.  
  52.         public static Rectangle Rotate(Rectangle rectangle, double angle)
  53.         {
  54.             var cosAngle = Math.Cos(angle);
  55.             var sinAngle = Math.Sin(angle);
  56.  
  57.             var width = Math.Abs(cosAngle) * rectangle.width;
  58.             var height = Math.Abs(sinAngle) * rectangle.height;
  59.  
  60.             var resultRectangle = new Rectangle(width, height);
  61.  
  62.             return resultRectangle;
  63.         }      
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement