From 856c35dbc7080922bfff7c10a7a844a9d0a1cd65 Mon Sep 17 00:00:00 2001 From: mo Date: Sat, 25 May 2019 15:27:51 -0600 Subject: start assignment 2 --- src/Q9/Number.java | 91 ------------------------------------------------------ 1 file changed, 91 deletions(-) delete mode 100644 src/Q9/Number.java (limited to 'src/Q9/Number.java') 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 iterate() { - ArrayList items = new ArrayList(); - ArrayList row = new ArrayList(); - 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); - } -} -- cgit v1.2.3