Guest User

Untitled

a guest
Apr 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. // if you call this method, it will in turn call other methods
  2.         // for calculation, i.e. abstracting.
  3.         // It calls PrintCircleDetails, which in turn will call
  4.         // GetCircleCircumference and GetCircleArea.
  5.         private void Print100DifferentCircleDetails()
  6.         {
  7.             var radius = 2;
  8.             var counter = 0;
  9.             // the while loop will iterate the code contained in its brackets ({})
  10.             // until the statement "counter < 100" is false.
  11.             // programming is 0 based that is why counter starts at 0 and the while loop
  12.             // continues until counter is greater than 99 aka 100. So we still get 100 loops, but since
  13.             // we start at 0 we end at 99.
  14.             while (counter < 100)
  15.             {
  16.                 PrintCircleDetails(radius);
  17.                
  18.                 // increment the radius for unique results to print.
  19.                 // if the number needs to stay the same for all 100 iterations
  20.                 // then just remove the below line.
  21.                 radius++;
  22.  
  23.                 // short hand for incrementing the counter variable by one.
  24.                 // in other words (counter = counter + 1).
  25.                 // Common shortcut that is provided in a lot of programming languages.
  26.                 counter++;
  27.             }
  28.         }
  29.  
  30.         private void PrintCircleDetails(int radius)
  31.         {
  32.             var circumference = GetCircleCircumference(radius);
  33.             var area = GetCircleArea(radius);
  34.  
  35.             // Now print off the results :-)
  36.             Print("Circle Radius = " + radius + " | Circle Circumference = " + circumference + " | Circle Area = " + area);
  37.         }
  38.  
  39.         private double GetCircleCircumference(int radius)
  40.         {
  41.             var pi = 3.14; // shortened PI but accurate enough for our purposes. mmmmmmmm pi
  42.             return 2 * pi * radius;
  43.         }
  44.  
  45.         private double GetCircleArea(int radius)
  46.         {
  47.             var pi = 3.14; // shortened PI but accurate enough for our purposes. mmmmmmmm pi
  48.             return pi * radius * radius;
  49.         }
Add Comment
Please, Sign In to add comment