|
| 1 | +package com.codedifferently.lesson6; |
| 2 | + |
| 3 | +import com.codedifferently.lesson6.util.Helpers; |
| 4 | +import org.springframework.boot.SpringApplication; |
| 5 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 6 | +import org.springframework.context.annotation.Configuration; |
| 7 | + |
| 8 | +@Configuration |
| 9 | +@SpringBootApplication(scanBasePackages = "com.codedifferently") |
| 10 | +public class Lesson6 { |
| 11 | + |
| 12 | + public static void main(String[] args) { |
| 13 | + var application = new SpringApplication(Lesson6.class); |
| 14 | + application.run(args); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * Returns true if the provided age meets the minimum US voting age and false otherwise. |
| 19 | + * |
| 20 | + * @param age The age to check. |
| 21 | + * @return True if the age corresponds to a voting age and false otherwise. |
| 22 | + */ |
| 23 | + public static boolean canVote(int age) { |
| 24 | + return false; |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * Compares two strings lexographically. |
| 29 | + * |
| 30 | + * @param value1 The first `String` to compare. |
| 31 | + * @param value2 The second `String` to compare. |
| 32 | + * @rerturn -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. |
| 33 | + */ |
| 34 | + public static int compareStrings(String a, String b) { |
| 35 | + // The distance will be a number less than 0 if string `a` is lexographically less than `b`, 1 |
| 36 | + // if it is greater, and 0 if the strings are equal. |
| 37 | + int distance = Helpers.computeLexographicDistance(a, b); |
| 38 | + |
| 39 | + // TODO(you): Finish this method. |
| 40 | + |
| 41 | + return 0; |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board |
| 46 | + * scale. See |
| 47 | + * https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale |
| 48 | + * for details. |
| 49 | + * |
| 50 | + * @param gpa The GPA value. |
| 51 | + * @return The letter grade ("A+", "A", "A-", "B+", etc.). |
| 52 | + */ |
| 53 | + public static String convertGpaToLetterGrade(double gpa) { |
| 54 | + return "F"; |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Computes the factorial of the given value of `n`. |
| 59 | + * |
| 60 | + * @param n The value for which to compute the factorial. |
| 61 | + * @return The factorial of n. |
| 62 | + */ |
| 63 | + public static int computeFactorial(int n) { |
| 64 | + return 0; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Adds all of the provided values and returns the sum. |
| 69 | + * |
| 70 | + * @param values The values to sum. |
| 71 | + * @return The sum of all the values. |
| 72 | + */ |
| 73 | + public static double addNumbers(double[] values) { |
| 74 | + return 0; |
| 75 | + } |
| 76 | + |
| 77 | + /** |
| 78 | + * Returns an array of the first `n` fibonacci numbers starting from 1. |
| 79 | + * |
| 80 | + * @param n The first `n` of fibonacci values to compute. |
| 81 | + * @return An array containing the first `n` fibonacci values. |
| 82 | + */ |
| 83 | + public static int[] getFirstNFibonacciNumbers(int n) { |
| 84 | + return null; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Finds a value in an array of values. |
| 89 | + * |
| 90 | + * @param values The values to search. |
| 91 | + * @param The left most index to search. |
| 92 | + * @param The right most index to search. |
| 93 | + * @param value The value to look for. |
| 94 | + * @return The index of the value if found in the array and -1 otherwise. |
| 95 | + */ |
| 96 | + public static int binarySearch(int[] values, int start, int end, int value) { |
| 97 | + if (end < start) { |
| 98 | + // |
| 99 | + return -1; |
| 100 | + } |
| 101 | + |
| 102 | + int pivotIndex = (start + end) / 2; // The index in the middle of the array. |
| 103 | + |
| 104 | + // TODO(you): Finish implementing this algorithm |
| 105 | + |
| 106 | + // If values[pivotIndex] is equal to value then return `pivotIndex`. |
| 107 | + // Else if values[pivotIndex] is greater than the value, then |
| 108 | + // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; |
| 109 | + // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. |
| 110 | + return -1; |
| 111 | + } |
| 112 | +} |
0 commit comments