summaryrefslogtreecommitdiff
path: root/src/Q9/Number.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Q9/Number.java')
-rw-r--r--src/Q9/Number.java91
1 files changed, 0 insertions, 91 deletions
diff --git a/src/Q9/Number.java b/src/Q9/Number.java
deleted file mode 100644
index e80cedf..0000000
--- a/src/Q9/Number.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- * Assignment 1, COMP268 Class: Number.java
- *
- * @description Provides static methods for operating on numeric values.
- * @author: mo khan Student ID: 3431709
- * @date May 8, 2019
- * @version 1.0
- */
-package Q9;
-
-import java.util.ArrayList;
-
-public class Number {
- /**
- * Checks to see if a number is divisible by 5.
- *
- * @param n the number to check for divisibility
- * @return true if the number is evenly divisible by 5
- */
- public static boolean isDivisibleBy5(int n) {
- return isDivisibleBy(n, 5);
- }
-
- /**
- * Checks to see if a number is divisible by 7
- *
- * @param n the number to check for divisibility
- * @return true if the number is evenly divisible by 7
- */
- public static boolean isDivisibleBy7(int n) {
- return isDivisibleBy(n, 7);
- }
-
- /**
- * Checks if a number is odd
- *
- * @param n the number to check
- * @return true if the number is an odd number.
- */
- public static boolean isOdd(int n) {
- return !isDivisibleBy(n, 2);
- }
-
- /**
- * Checks if a number is prime. This is naive implementation of the prime number check that will
- * blow the stack for any sufficiently large number.
- *
- * @param n the number to check
- * @return true if the number is a prime number
- */
- public static boolean isPrime(int n) {
- if (n <= 1) return false;
-
- for (int i = n - 1; i > 1; i--) if (isDivisibleBy(n, i)) return false;
-
- return true;
- }
-
- /**
- * Checks to see if a number is divisible by denominator
- *
- * @param n the number to check for divisibility
- * @param denominator the number to see if n is evenly divisible by
- * @return true if the number is evenly divisible by denominator
- */
- public static boolean isDivisibleBy(int n, int denominator) {
- return n % denominator == 0;
- }
-
- /** @return a list of strings for each number between 0 and 113 */
- public static ArrayList<String> iterate() {
- ArrayList<String> items = new ArrayList<String>();
- ArrayList<String> row = new ArrayList<String>();
- for (Integer i = 0; i < 113; i++) {
- row.clear();
- row.add(String.format("%d", i));
-
- if (isOdd(i)) row.add(String.format("%d is odd", i));
- if (isDivisibleBy5(i)) row.add("hi five");
- if (isDivisibleBy7(i + (i + 1))) row.add("wow");
- if (isPrime(i)) row.add("prime");
-
- items.add(String.join(",", row));
- }
- return items;
- }
-
- public static void main(String[] args) {
- for (String item : Number.iterate()) System.out.println(item);
- }
-}