Skip to content

Commit 98ba62f

Browse files
committed
FizzBuzz:
- Add FizzBuzz Class - Move FizzBuzz logic from main application to FizzBuzzLogic Method in FizzBuzz class
1 parent 0a881c2 commit 98ba62f

File tree

13 files changed

+60
-32
lines changed

13 files changed

+60
-32
lines changed

.vs/VSWorkspaceState.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"\\FizzBuzz\\FizzBuzz",
66
"\\FizzBuzz\\FizzBuzz\\FizzBuzz"
77
],
8-
"SelectedNode": "\\Readme.md",
8+
"SelectedNode": "\\FizzBuzz\\FizzBuzz\\FizzBuzz\\Program.cs",
99
"PreviewInSolutionExplorer": false
1010
}

.vs/c_sharp_portfolio/v16/.suo

-5 KB
Binary file not shown.

.vs/slnx.sqlite

0 Bytes
Binary file not shown.
14 KB
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// FizzBuzz
2+
// by Steven Partlow
3+
// DATE: 02/06/2023
4+
5+
// FIZZ BUZZ Class Defintion
6+
7+
using System;
8+
9+
namespace FizzBuzz
10+
{
11+
12+
class FizzBuzz // A class for the main FizzBuzz application logic
13+
{
14+
// Definition for method FizzBuzzLogic, the number entered by the user in the main program is passed in, the method does not return anything
15+
public static void FizzBuzzLogic(double userNum)
16+
{
17+
18+
// FizzBuzz LOGIC
19+
if (userNum % 3 == 0 && userNum % 5 == 0) // If the the value the user entered is divisable by three and five then
20+
{
21+
Console.WriteLine("\nFizzBuzz"); // Output 'FizzBuzz' to the console
22+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
23+
Console.ReadKey(); // Peuse the application until the user presses a key
24+
} // End IF
25+
26+
// Fizz LOGIC
27+
else if (userNum % 3 == 0) // If the the value the user entered is divisable by three then
28+
{
29+
Console.WriteLine("\nFizz"); // Output 'Fizz' to the console
30+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
31+
Console.ReadKey(); // Peuse the application until the user presses a key
32+
} // End ELSE IF
33+
34+
// Buzz LOGIC
35+
else if (userNum % 5 == 0) // If the the value the user entered is divisable by five then
36+
{
37+
Console.WriteLine("\nBuzz"); // Output 'Buzz' to the console
38+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
39+
Console.ReadKey(); // Peuse the application until the user presses a key
40+
} // End ELSE IF
41+
42+
// LOGIC for any other outcome
43+
else // If none of the the three condition above are met
44+
{
45+
Console.WriteLine("\nSorry not Fizz or Buzz :("); // Output this text to the console
46+
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
47+
Console.ReadKey(); // Peuse the application until the user presses a key
48+
} // End ELSE
49+
50+
} // End FizzBuzzLogic METHOD
51+
52+
} // END FizzBuzz CLASS
53+
54+
} // END FizzBuzz NAMESPACE

FizzBuzz/FizzBuzz/FizzBuzz/FizzBuzz.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<Reference Include="System.Xml" />
4444
</ItemGroup>
4545
<ItemGroup>
46+
<Compile Include="FizzBuzz.cs" />
4647
<Compile Include="Program.cs" />
4748
<Compile Include="Properties\AssemblyInfo.cs" />
4849
</ItemGroup>

FizzBuzz/FizzBuzz/FizzBuzz/Program.cs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// FizzBuzz
22
// by Steven Partlow
3-
// DATE: 01/06/2023
3+
// DATE: 02/06/2023
44

55
/* A C# version of the FizzBuzz problem, uses a TRY / CATCH block to exceptions, check that the number entered is a whole number with no
66
decimal places , then checks for FizzBuzz (divisable by 3 and 5), Fizz (divisable by 3) and Buzz (divisable by 5) before a general message
@@ -63,35 +63,8 @@ static void Main(string[] args)
6363

6464
// End of CATCH Block
6565

66-
// FizzBuzz LOGIC
67-
if (userNum % 3 == 0 && userNum % 5 == 0) // If the the value the user entered is divisable by three and five then
68-
{
69-
Console.WriteLine("\nFizzBuzz"); // Output 'FizzBuzz' to the console
70-
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
71-
Console.ReadKey(); // Peuse the application until the user presses a key
72-
break; // Break the WHILE loop
73-
} // End IF
74-
else if (userNum % 3 == 0) // If the the value the user entered is divisable by three then
75-
{
76-
Console.WriteLine("\nFizz"); // Output 'Fizz' to the console
77-
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
78-
Console.ReadKey(); // Peuse the application until the user presses a key
79-
break; // Break the WHILE loop
80-
} // End ELSE IF
81-
else if (userNum % 5 == 0) // If the the value the user entered is divisable by five then
82-
{
83-
Console.WriteLine("\nBuzz"); // Output 'Buzz' to the console
84-
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
85-
Console.ReadKey(); // Peuse the application until the user presses a key
86-
break; // Break the WHILE loop
87-
} // End ELSE IF
88-
else // If none of the the three condition above are met
89-
{
90-
Console.WriteLine("\nSorry not Fizz or Buzz :("); // Output this text to the console
91-
Console.WriteLine("\nThe application will now exit, Press any KEY to continue.\n"); // Output this text to the console
92-
Console.ReadKey(); // Peuse the application until the user presses a key
93-
break; // Break the WHILE loop
94-
} // End ELSE
66+
FizzBuzz.FizzBuzzLogic(userNum);
67+
break;
9568

9669
} //End WHILE
9770

0 Bytes
Binary file not shown.
4 KB
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)