From 54d548d23824644de841b123e7386511610abe04 Mon Sep 17 00:00:00 2001 From: nilejack Date: Mon, 14 Oct 2024 12:20:56 +0000 Subject: [PATCH 1/7] feat:adds lesson_07/conditionals-nilejackson --- lesson_07/conditionals/src/lesson7.ts | 91 ++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 8 deletions(-) diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts index 52f45df8b..977fe04a7 100644 --- a/lesson_07/conditionals/src/lesson7.ts +++ b/lesson_07/conditionals/src/lesson7.ts @@ -1,15 +1,22 @@ import { computeLexicographicDistance } from "./util.js"; -/** +/** * Returns true if the provided age meets the minimum US voting age and false otherwise. * * @param age The age to check. * @return True if the age corresponds to a voting age and false otherwise. - */ + */ + export function canVote(age: number): boolean { + return false; +if(age >= 18) { + return true; +} else { return false; -} +} +console.log(age >= 18); +} /** * Compares two strings lexicographically. * @@ -20,11 +27,21 @@ export function canVote(age: number): boolean { export function compareStrings(a: string, b: string): number { // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 // if it is greater, and 0 if the strings are equal. - const distance = computeLexicographicDistance(a, b); + const distance = computeLexicographicDistance(a, b); + distance; a; 1; + distance; b; 1; { + if(distance > 0) { + return 1; //equal distances + } else if(distance <0 ) { + return -1; //unequal distances + } else if(distance === 0) { + return 0; + } +} + //This is just an idea(That's probably wrong)/ // TODO(you): Finish this method. - - return 0; + } /** @@ -38,6 +55,30 @@ export function compareStrings(a: string, b: string): number { */ export function convertGpaToLetterGrade(gpa: number): string { return "F"; +if (gpa == 4.0) { + return "A"; +} else if (gpa <= 3.99 && gpa >= 3.7) { + return "A-"; +} else if (gpa <= 3.69 && gpa >= 3.3) { + return "B+"; +} else if (gpa <= 3.29 && gpa >= 3.0) { + return "B"; +} else if (gpa <= 2.99 && gpa >= 2.7) { + return "B-"; +} else if (gpa <= 2.69 && gpa >= 2.3) { + return "C+"; +} else if (gpa <= 2.29 && gpa >= 2.0) { + return "C"; +} else if (gpa <= 1.99 && gpa >= 1.7) { + return "C-"; +} else if (gpa <= 1.69 && gpa >= 1.3) { + return "D+"; +} else if (gpa <= 1.29 && gpa >= 1.0) { + return "D"; +} else { + return "F"; +} + } /** @@ -48,6 +89,12 @@ export function convertGpaToLetterGrade(gpa: number): string { */ export function computeFactorial(n: number): number { return 0; + let product = 1; + for (let i = 1; 1 <= n; i++) { + product *= i; + } + + return product; } /** @@ -58,6 +105,10 @@ export function computeFactorial(n: number): number { */ export function addNumbers(values: number[]): number { return 0; + let sum = 0; for(const value of values) { + sum + value; + } + return sum; } /** @@ -67,7 +118,17 @@ export function addNumbers(values: number[]): number { * @return An array containing the first `n` Fibonacci values. */ export function getFirstNFibonacciNumbers(n: number): number[] { - return []; + if (n < 1) { + return []; + } + + const fibonacci: number[] = [1, 1]; // The function starts with the first two Fibonacci numbers + + for (let i = 2; i < n; i++) { + fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; // Here the sum of the preceeding expression(?) is iterated with the number directly preceeding it + } + + return fibonacci.slice(0, n); // Return only the first n Fibonacci numbers } /** @@ -86,12 +147,26 @@ export function binarySearch( value: number, ): number { if (end < start) { - // The range is not valid so just return -1. + return -1; } + + + + const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. + if (values[pivotIndex] === value) { + return pivotIndex; + + } else if (values[pivotIndex] > value) { + return binarySearch(values, start, pivotIndex -1 ,value); + return value; + } else { + return (binarySearch(values, pivotIndex +1, end, value)); + + } // TODO(you): Finish implementing this algorithm // If values[pivotIndex] is equal to value then return `pivotIndex`. From b99782b298a96106df869d378c3a9976a0ae5cfc Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 12:58:38 +0000 Subject: [PATCH 2/7] Feat: Adds/NileJack09-hw --- .../dataprovider/NileJackProvider.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java new file mode 100644 index 000000000..437665660 --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java @@ -0,0 +1,22 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; +import org.springframework.stereotype.Service; + +@Service +public class AnthonyMaysProvider extends DataProvider { + public String getProviderName() { + return "anthonymays"; + } + + public Map getColumnTypeByName() { + return Map.of( + "column1", Integer.class, + "column2", String.class, + "column3", Boolean.class, + "column4", Float.class, + "column5", Double.class, + "column6", Long.class, + "column7", Short.class); + } +} From e1d58d5cacda176004b6ba67c77bea83d79d9342 Mon Sep 17 00:00:00 2001 From: Nile Jackson Date: Tue, 15 Oct 2024 09:03:43 -0400 Subject: [PATCH 3/7] Delete lesson_07/conditionals/src/lesson7.ts Unnecessary file --- lesson_07/conditionals/src/lesson7.ts | 177 -------------------------- 1 file changed, 177 deletions(-) delete mode 100644 lesson_07/conditionals/src/lesson7.ts diff --git a/lesson_07/conditionals/src/lesson7.ts b/lesson_07/conditionals/src/lesson7.ts deleted file mode 100644 index 977fe04a7..000000000 --- a/lesson_07/conditionals/src/lesson7.ts +++ /dev/null @@ -1,177 +0,0 @@ -import { computeLexicographicDistance } from "./util.js"; - -/** - * Returns true if the provided age meets the minimum US voting age and false otherwise. - * - * @param age The age to check. - * @return True if the age corresponds to a voting age and false otherwise. - */ - -export function canVote(age: number): boolean { - return false; -if(age >= 18) { - return true; -} else { - return false; -} -console.log(age >= 18); - -} -/** - * Compares two strings lexicographically. - * - * @param a The first `string` to compare. - * @param b The second `string` to compare. - * @return -1 if a is less than b, 1 if a is greater than b, and 0 otherwise. - */ -export function compareStrings(a: string, b: string): number { - // The distance will be a number less than 0 if string `a` is lexicographically less than `b`, 1 - // if it is greater, and 0 if the strings are equal. - const distance = computeLexicographicDistance(a, b); - distance; a; 1; - distance; b; 1; { - if(distance > 0) { - return 1; //equal distances - } else if(distance <0 ) { - return -1; //unequal distances - } else if(distance === 0) { - return 0; - } - -} - //This is just an idea(That's probably wrong)/ - // TODO(you): Finish this method. - -} - -/** - * Converts a GPA on the 4.0 scale to the corresponding letter grade using the college board - * scale. See - * https://bigfuture.collegeboard.org/plan-for-college/college-basics/how-to-convert-gpa-4.0-scale - * for details. - * - * @param gpa The GPA value. - * @return The letter grade ("A+", "A", "A-", "B+", etc.). - */ -export function convertGpaToLetterGrade(gpa: number): string { - return "F"; -if (gpa == 4.0) { - return "A"; -} else if (gpa <= 3.99 && gpa >= 3.7) { - return "A-"; -} else if (gpa <= 3.69 && gpa >= 3.3) { - return "B+"; -} else if (gpa <= 3.29 && gpa >= 3.0) { - return "B"; -} else if (gpa <= 2.99 && gpa >= 2.7) { - return "B-"; -} else if (gpa <= 2.69 && gpa >= 2.3) { - return "C+"; -} else if (gpa <= 2.29 && gpa >= 2.0) { - return "C"; -} else if (gpa <= 1.99 && gpa >= 1.7) { - return "C-"; -} else if (gpa <= 1.69 && gpa >= 1.3) { - return "D+"; -} else if (gpa <= 1.29 && gpa >= 1.0) { - return "D"; -} else { - return "F"; -} - -} - -/** - * Computes the factorial of the given value of `n`. - * - * @param n The value for which to compute the factorial. - * @return The factorial of n. - */ -export function computeFactorial(n: number): number { - return 0; - let product = 1; - for (let i = 1; 1 <= n; i++) { - product *= i; - } - - return product; -} - -/** - * Adds all of the provided values and returns the sum. - * - * @param values The values to sum. - * @return The sum of all the values. - */ -export function addNumbers(values: number[]): number { - return 0; - let sum = 0; for(const value of values) { - sum + value; - } - return sum; -} - -/** - * Returns an array of the first `n` Fibonacci numbers starting from 1. - * - * @param n The first `n` of Fibonacci values to compute. - * @return An array containing the first `n` Fibonacci values. - */ -export function getFirstNFibonacciNumbers(n: number): number[] { - if (n < 1) { - return []; - } - - const fibonacci: number[] = [1, 1]; // The function starts with the first two Fibonacci numbers - - for (let i = 2; i < n; i++) { - fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; // Here the sum of the preceeding expression(?) is iterated with the number directly preceeding it - } - - return fibonacci.slice(0, n); // Return only the first n Fibonacci numbers -} - -/** - * Finds a value in an array of values. - * - * @param values The values to search. - * @param start The left most index to search. - * @param end The right most index to search. - * @param value The value to look for. - * @return The index of the value if found in the array and -1 otherwise. - */ -export function binarySearch( - values: number[], - start: number, - end: number, - value: number, -): number { - if (end < start) { - - return -1; - } - - - - - - const pivotIndex = Math.floor((start + end) / 2); // The index in the middle of the array. - - if (values[pivotIndex] === value) { - return pivotIndex; - - } else if (values[pivotIndex] > value) { - return binarySearch(values, start, pivotIndex -1 ,value); - return value; - } else { - return (binarySearch(values, pivotIndex +1, end, value)); - - } - // TODO(you): Finish implementing this algorithm - - // If values[pivotIndex] is equal to value then return `pivotIndex`. - // Else if values[pivotIndex] is greater than the value, then - // call `binarySearch(values, start, pivotIndex - 1, value)` and return its value; - // Else call `binarySearch(values, pivotIndex + 1, end, value)` and return its value. - return -1; -} From 74a28d70ed13de08a894ba440d7ba10586739fdb Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 13:08:24 +0000 Subject: [PATCH 4/7] Feat:adds/NileJack.ProviderFileHW --- .../dataprovider/NileJackProvider.java | 19 ++-- .../src/main/resources/data/nilejack.json | 93 +++++++++++++++++++ 2 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 lesson_09/types/types_app/src/main/resources/data/nilejack.json diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java index 437665660..d866d6741 100644 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java @@ -1,22 +1,23 @@ package com.codedifferently.lesson9.dataprovider; import java.util.Map; + import org.springframework.stereotype.Service; @Service -public class AnthonyMaysProvider extends DataProvider { +public class NileJackProvider extends DataProvider { public String getProviderName() { - return "anthonymays"; + return "nilejack"; } public Map getColumnTypeByName() { return Map.of( - "column1", Integer.class, - "column2", String.class, - "column3", Boolean.class, - "column4", Float.class, - "column5", Double.class, - "column6", Long.class, - "column7", Short.class); + "column1", Float.class, + "column2", Integer.class, + "column3", Short.class, + "column4", String.class, + "column5", Boolean.class, + "column6", Double.class, + "column7", Long.class); } } diff --git a/lesson_09/types/types_app/src/main/resources/data/nilejack.json b/lesson_09/types/types_app/src/main/resources/data/nilejack.json new file mode 100644 index 000000000..4c55c94f9 --- /dev/null +++ b/lesson_09/types/types_app/src/main/resources/data/nilejack.json @@ -0,0 +1,93 @@ +[ + package com.code + { + "column1", Float.class, + "column2", Integer.class, + "column3", Short.class , + "column4", String.class , + "column5", Boolean.class, + "column6", Double.class , + "column7", Long.class , + }, + { + "column1": "2.9218724E38", + "column2": "5982", + "column3": "1.6613559878792952E308", + "column4": "kcy91i4", + "column5": "true", + "column6": "467285300", + "column7": "717033365520104960" + }, + { + "column1": "2.6791138E38", + "column2": "3087", + "column3": "1.4531283019824207E307", + "column4": "5gdku", + "column5": "false", + "column6": "1339783318", + "column7": "8609205761188083712" + }, + { + "column1": "2.7654423E38", + "column2": "22857", + "column3": "1.3125501238039668E308", + "column4": "2ab3nxz", + "column5": "false", + "column6": "1166125928", + "column7": "3850529467803900928" + }, + { + "column1": "7.978512E37", + "column2": "30614", + "column3": "1.0016443609479493E308", + "column4": "jh490kp25z8", + "column5": "true", + "column6": "684136174", + "column7": "2530680619863128064" + }, + { + "column1": "5.8039073E37", + "column2": "4886", + "column3": "1.3705152061964327E308", + "column4": "ak5we9tfr", + "column5": "false", + "column6": "728654337", + "column7": "1671706500207470592" + }, + { + "column1": "5.139036E37", + "column2": "9019", + "column3": "1.2523590249164425E308", + "column4": "5tefqwblim3", + "column5": "true", + "column6": "14150416", + "column7": "4871306662885839872" + }, + { + "column1": "2.6188858E37", + "column2": "2398", + "column3": "1.444754024326182E308", + "column4": "w8hfk7nl1s", + "column5": "false", + "column6": "2000776131", + "column7": "8280646876683382784" + }, + { + "column1": "3.1079513E38", + "column2": "32074", + "column3": "9.799167831142151E307", + "column4": "glx5ze96mk", + "column5": "false", + "column6": "2134631706", + "column7": "3840235999993978368" + }, + { + "column1": "1.1965353E38", + "column2": "30848", + "column3": "1.0643709914035035E308", + "column4": "s51gxi7hm3", + "column5": "false", + "column6": "1598587760", + "column7": "8883551926143157248" + } +] \ No newline at end of file From d308af7b655c99fa6aba462703e24cc0eb6d10fd Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 13:12:56 +0000 Subject: [PATCH 5/7] Feat: Changes for HW --- .../dataprovider/AnthonyMaysProvider.java | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java deleted file mode 100644 index 437665660..000000000 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/AnthonyMaysProvider.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.codedifferently.lesson9.dataprovider; - -import java.util.Map; -import org.springframework.stereotype.Service; - -@Service -public class AnthonyMaysProvider extends DataProvider { - public String getProviderName() { - return "anthonymays"; - } - - public Map getColumnTypeByName() { - return Map.of( - "column1", Integer.class, - "column2", String.class, - "column3", Boolean.class, - "column4", Float.class, - "column5", Double.class, - "column6", Long.class, - "column7", Short.class); - } -} From d82f060f4ba371f93a628011e804582ba3edd091 Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 14:09:16 +0000 Subject: [PATCH 6/7] feat: adds/Customized/DataTypesHW09 --- .../lesson9/dataprovider/DataProvider.java | 48 +------------------ .../dataprovider/NileJackProvider.java | 1 + .../dataprovider/NileJacksonProvider.java | 23 +++++++++ .../src/main/resources/data/nilejack.json | 17 ++++--- 4 files changed, 33 insertions(+), 56 deletions(-) create mode 100644 lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java index 595357609..f7dc65528 100644 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/DataProvider.java @@ -1,51 +1,5 @@ package com.codedifferently.lesson9.dataprovider; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +public class DataProvider { -/** - * This class is a base class for data providers. It provides a method for parsing data from a list - * of maps. - */ -public abstract class DataProvider { - /** Returns the name of the provider. */ - public abstract String getProviderName(); - - /** Gets a map of column types keyed by column name. */ - public abstract Map getColumnTypeByName(); - - /** - * Given a list of data objects, returns the list with values converted to the appropriate type. - * - * @param data A list of data objects containing values keyed by column name. - * @return A new list with object values converted to the appropriate type. - */ - public List> parseData(List> data) throws Exception { - Map columnTypeByName = getColumnTypeByName(); - return data.stream().map(row -> parseRow(columnTypeByName, row)).collect(Collectors.toList()); - } - - /** - * Parses a single row of data using the provided column types mapping. - * - * @param columnTypeByName A map containing the type of a column keyed by its name. - * @param row A bag of values keyed by column name. - * @return A new list of data values converted to the appropriate type. - */ - private Map parseRow( - Map columnTypeByName, Map row) { - var parsedRow = new java.util.HashMap(); - row.forEach( - (key, value) -> { - Class type = columnTypeByName.get(key); - try { - parsedRow.put(key, type.getConstructor(String.class).newInstance(value)); - } catch (Exception e) { - throw new RuntimeException( - "Error parsing data for " + key + " as type " + type.getName()); - } - }); - return parsedRow; - } } diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java index d866d6741..a5bd8b0c8 100644 --- a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJackProvider.java @@ -10,6 +10,7 @@ public String getProviderName() { return "nilejack"; } + @SuppressWarnings("rawtypes") public Map getColumnTypeByName() { return Map.of( "column1", Float.class, diff --git a/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java new file mode 100644 index 000000000..fe24b0d4a --- /dev/null +++ b/lesson_09/types/types_app/src/main/java/com/codedifferently/lesson9/dataprovider/NileJacksonProvider.java @@ -0,0 +1,23 @@ +package com.codedifferently.lesson9.dataprovider; + +import java.util.Map; + +import org.springframework.stereotype.Service; + +@Service +public class NileJackProvider extends DataProvider { + public String getProviderName() { + return "nilejack"; + } + + public Map getColumnTypeByName() { + return Map.of( + "column1", Float.class, + "column2", Integer.class, + "column3", Short.class, + "column4", String.class, + "column5", Boolean.class, + "column6", Double.class, + "column7", Long.class); + } +} \ No newline at end of file diff --git a/lesson_09/types/types_app/src/main/resources/data/nilejack.json b/lesson_09/types/types_app/src/main/resources/data/nilejack.json index 4c55c94f9..03fa75333 100644 --- a/lesson_09/types/types_app/src/main/resources/data/nilejack.json +++ b/lesson_09/types/types_app/src/main/resources/data/nilejack.json @@ -1,13 +1,12 @@ -[ - package com.code +[ { - "column1", Float.class, - "column2", Integer.class, - "column3", Short.class , - "column4", String.class , - "column5", Boolean.class, - "column6", Double.class , - "column7", Long.class , + "column1": "2.788476E38", + "column2": "23906", + "column3": "1.951334947469109E306", + "column4": "4vynlcbme89", + "column5": "true", + "column6": "1946511983", + "column7": "871716420668780160" }, { "column1": "2.9218724E38", From fd134c8cb9e59cecad695cabceabb657000a1740 Mon Sep 17 00:00:00 2001 From: nilejack Date: Tue, 15 Oct 2024 14:10:33 +0000 Subject: [PATCH 7/7] Feat: adds/NileJackson/Lesson09Hw --- .../java/com/codedifferently/lesson9/Lesson9Test.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java b/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java index 397136446..0083c4ae1 100644 --- a/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java +++ b/lesson_09/types/types_app/src/test/java/com/codedifferently/lesson9/Lesson9Test.java @@ -1,14 +1,12 @@ package com.codedifferently.lesson9; -import static org.assertj.core.api.Assertions.assertThat; - -import com.codedifferently.lesson9.dataprovider.DataProvider; -import com.codedifferently.lesson9.loader.DataFileLoader; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,6 +14,9 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; +import com.codedifferently.lesson9.dataprovider.DataProvider; +import com.codedifferently.lesson9.loader.DataFileLoader; + @SpringBootTest @ContextConfiguration(classes = Lesson9.class) @ExtendWith(SoftAssertionsExtension.class)