Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // if you call this method, it will in turn call other methods
- // for calculation, i.e. abstracting.
- // It calls PrintCircleDetails, which in turn will call
- // GetCircleCircumference and GetCircleArea.
- private void Print100DifferentCircleDetails()
- {
- var radius = 2;
- var counter = 0;
- // the while loop will iterate the code contained in its brackets ({})
- // until the statement "counter < 100" is false.
- // programming is 0 based that is why counter starts at 0 and the while loop
- // continues until counter is greater than 99 aka 100. So we still get 100 loops, but since
- // we start at 0 we end at 99.
- while (counter < 100)
- {
- PrintCircleDetails(radius);
- // increment the radius for unique results to print.
- // if the number needs to stay the same for all 100 iterations
- // then just remove the below line.
- radius++;
- // short hand for incrementing the counter variable by one.
- // in other words (counter = counter + 1).
- // Common shortcut that is provided in a lot of programming languages.
- counter++;
- }
- }
- private void PrintCircleDetails(int radius)
- {
- var circumference = GetCircleCircumference(radius);
- var area = GetCircleArea(radius);
- // Now print off the results :-)
- Print("Circle Radius = " + radius + " | Circle Circumference = " + circumference + " | Circle Area = " + area);
- }
- private double GetCircleCircumference(int radius)
- {
- var pi = 3.14; // shortened PI but accurate enough for our purposes. mmmmmmmm pi
- return 2 * pi * radius;
- }
- private double GetCircleArea(int radius)
- {
- var pi = 3.14; // shortened PI but accurate enough for our purposes. mmmmmmmm pi
- return pi * radius * radius;
- }
Add Comment
Please, Sign In to add comment