SHOW:
|
|
- or go back to the newest paste.
1 | package com.myimportantcompany.fizzbuzz; | |
2 | ||
3 | /** | |
4 | * This is the main class for executing the FizzBuzz Program | |
5 | * @author Simon | |
6 | * | |
7 | */ | |
8 | public class Main { | |
9 | ||
10 | /** | |
11 | * This is the main function for the Program, also called the entry point. | |
12 | * @param args These are ignored in this program | |
13 | */ | |
14 | public static void main(String[] args) { | |
15 | int limitForFizzBuzzProgram = 100; | |
16 | for (int forLoopCounter = 0; forLoopCounter <= limitForFizzBuzzProgram; forLoopCounter = forLoopCounter + 1) { | |
17 | ||
18 | if(isNumberDivisibleByFiveAndThreeWithoutRemainder(forLoopCounter)) { | |
19 | System.out.println(FizzBuzz.FIZZBUZZ); | |
20 | } else if(isNumberDivisibleByFiveWithoutRemainder(forLoopCounter)) { | |
21 | System.out.println(Buzz.BUZZ); | |
22 | } else if(isNumberDivisibleByThreeWithoutRemainder(forLoopCounter)) { | |
23 | System.out.println(Fizz.FIZZ); | |
24 | } else { | |
25 | System.out.println(forLoopCounter); | |
26 | } | |
27 | } | |
28 | } | |
29 | ||
30 | /** | |
31 | * This function checks whether a given number is divisible by 3 without a remainder | |
32 | * @param number the number to be checked | |
33 | * @return True if the number is divisible by 3 without a remainder, false otherwise | |
34 | */ | |
35 | public static boolean isNumberDivisibleByThreeWithoutRemainder(int number) { | |
36 | if (((number / 3) * 3) == number) { | |
37 | return true; | |
38 | } else { | |
39 | return false; | |
40 | } | |
41 | } | |
42 | ||
43 | /** | |
44 | * This function checks whether a given number is divisible by 5 without a remainder | |
45 | * @param number the number to be checked | |
46 | * @return True if the number is divisible by 5 without a remainder, false otherwise | |
47 | */ | |
48 | public static boolean isNumberDivisibleByFiveWithoutRemainder(int number) { | |
49 | if (((number / 5) * 5) == number) { | |
50 | return true; | |
51 | } else { | |
52 | return false; | |
53 | } | |
54 | } | |
55 | ||
56 | /** | |
57 | * This function checks whether a given number is divisible by 5 and 3without a remainder | |
58 | * @param number the number to be checked | |
59 | * @return True if the number is divisible by 5 and 3 without a remainder, false otherwise | |
60 | */ | |
61 | public static boolean isNumberDivisibleByFiveAndThreeWithoutRemainder( | |
62 | int number) { | |
63 | boolean checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false; | |
64 | if (((number / 3) * 3) == number) { | |
65 | checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = true; | |
66 | } else { | |
67 | checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false; | |
68 | } | |
69 | ||
70 | if (((number / 5) * 5) == number) { | |
71 | checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = true; | |
72 | } else { | |
73 | checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder = false; | |
74 | } | |
75 | return checkVariableForIsNumberDivisibleByFiveAndThreeWithoutRemainder; | |
76 | } | |
77 | } |