Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: adds lesson 07 content #178

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7a83026
chore: sets up new project
anthonydmays Mar 8, 2024
3a07a93
feat: adds method stubs to implement
anthonydmays Mar 9, 2024
407c1cb
feat: adds additional assignment question and configures build
anthonydmays Mar 9, 2024
04df508
chore: adds build action
anthonydmays Mar 9, 2024
f2f510c
Merge branch 'code-differently:main' into lesson_06
anthonydmays Mar 9, 2024
6cec0be
chore: adds helper method for string comparison
anthonydmays Mar 10, 2024
2293687
chore: adds more documentation
anthonydmays Mar 10, 2024
2b12076
chore: adding more test cases for gpa method
anthonydmays Mar 10, 2024
8db111f
chore: refactors string function
anthonydmays Mar 10, 2024
22aa311
chore: adds more documentation
anthonydmays Mar 10, 2024
060bf6a
docs: adds homework details
anthonydmays Mar 10, 2024
ab821c0
tests: bolstering binary search test
anthonydmays Mar 10, 2024
c9a7730
chore: undoing less6 change
anthonydmays Mar 10, 2024
ca954a0
chore: adding return for binary search
anthonydmays Mar 10, 2024
28c7183
docs: updates assigned reading
anthonydmays Mar 10, 2024
8654b42
test: updates doco
anthonydmays Mar 10, 2024
e57393f
tests: add exception cases
anthonydmays Mar 10, 2024
94d9a5e
chore: updating file organization
anthonydmays Mar 10, 2024
ee4e45c
chore: adds Helpers file
anthonydmays Mar 10, 2024
b31211e
feat: sets up exercises
anthonydmays Mar 10, 2024
3df0889
chore: refactoring files
anthonydmays Mar 10, 2024
1cc7dd5
chore: adding method doco
anthonydmays Mar 10, 2024
abf67ef
chore: adds build checks for L7
anthonydmays Mar 10, 2024
febf14e
Merge branch 'code-differently:main' into lesson_07
anthonydmays Mar 11, 2024
da39232
chore: merging upstream
anthonydmays Mar 11, 2024
f082106
chore: merging upstream
anthonydmays Mar 11, 2024
4a7ee5a
chore: adds helper method for string comparison
anthonydmays Mar 10, 2024
23094ca
Merge branch 'main' into lesson_07
anthonydmays Mar 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/check_lesson_07_pr.yml
@@ -0,0 +1,33 @@
name: Check Lesson 07 Pull Request

on:
pull_request:
branches: [ "main" ]
paths:
- "lesson_07/exceptions/**"

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build Lesson 07 with Gradle Wrapper
working-directory: ./lesson_07/exceptions
run: ./gradlew check


4 changes: 4 additions & 0 deletions .github/workflows/check_push.yml
Expand Up @@ -51,6 +51,10 @@ jobs:
working-directory: ./lesson_06/conditionals
run: ./gradlew assemble && ./gradlew spotlessCheck

- name: Build Lesson 07 with Gradle Wrapper
working-directory: ./lesson_07/exceptions
run: ./gradlew assemble && ./gradlew spotlessCheck

- name: Build Shared Lib with Gradle Wrapper
working-directory: ./lib/java/codedifferently-instructional
run: ./gradlew check
Expand Down
2 changes: 1 addition & 1 deletion lesson_06/README.md
Expand Up @@ -10,4 +10,4 @@
This exercise will provide you ample opportunities to practice your understanding of conditional expressions and loops. To complete this assignment, implement the functions in [Lesson6.java][lesson6-file], ensure the tests pass, and submit a PR. Remember to use the [Conventional Commits][conventional-commits] spec for your commit messages and pull requests.

[lesson6-file]: ./conditionals/conditionals_app/src/main/java/com/codedifferently/lesson6/Lesson6.java
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/
[conventional-commits]: https://www.conventionalcommits.org/en/v1.0.0/
Expand Up @@ -121,4 +121,4 @@ void testBinarySearch() {
// Test for value not present in the array
assertThat(Lesson6.binarySearch(values, 0, values.length - 1, 4)).isEqualTo(-1);
}
}
}
3 changes: 3 additions & 0 deletions lesson_07/README.md
@@ -0,0 +1,3 @@
# Lesson 07

TODO(anthonydmays): Finish this
9 changes: 9 additions & 0 deletions lesson_07/exceptions/.gitattributes
@@ -0,0 +1,9 @@
#
# https://help.github.com/articles/dealing-with-line-endings/
#
# Linux start script should use lf
/gradlew text eol=lf

# These are Windows script files and should use crlf
*.bat text eol=crlf

5 changes: 5 additions & 0 deletions lesson_07/exceptions/.gitignore
@@ -0,0 +1,5 @@
# Ignore Gradle project-specific cache directory
.gradle

# Ignore Gradle build output directory
build
64 changes: 64 additions & 0 deletions lesson_07/exceptions/exceptions_app/build.gradle.kts
@@ -0,0 +1,64 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
application
eclipse
id("com.diffplug.spotless") version "6.25.0"
id("org.springframework.boot") version "3.2.2"
id("com.adarshr.test-logger") version "4.0.0"
}

apply(plugin = "io.spring.dependency-management")

repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}

dependencies {
// Use JUnit Jupiter for testing.
testImplementation("com.codedifferently.instructional:instructional-lib")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("org.assertj:assertj-core:3.25.1")
testImplementation("at.favre.lib:bcrypt:0.10.2")

// This dependency is used by the application.
implementation("com.codedifferently.instructional:instructional-lib")
implementation("com.google.guava:guava:31.1-jre")
implementation("com.google.code.gson:gson:2.10.1")
implementation("org.projectlombok:lombok:1.18.30")
implementation("org.springframework.boot:spring-boot-starter")
}

application {
// Define the main class for the application.
mainClass.set("com.codedifferently.lesson6.Lesson6")
}

tasks.named<Test>("test") {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}


configure<com.diffplug.gradle.spotless.SpotlessExtension> {

format("misc", {
// define the files to apply `misc` to
target("*.gradle", ".gitattributes", ".gitignore")

// define the steps to apply to those files
trimTrailingWhitespace()
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
endWithNewline()
})

java {
// don't need to set target, it is inferred from java

// apply a specific flavor of google-java-format
googleJavaFormat()
// fix formatting of type annotations
formatAnnotations()
}
}
@@ -0,0 +1,116 @@
package com.codedifferently.lesson7;

import com.codedifferently.lesson7.gpa.GpaToLetterGradeConverter;
import com.codedifferently.lesson7.util.Helpers;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;

@Configuration
@SpringBootApplication(scanBasePackages = "com.codedifferently")
public class Lesson7 {

public static void main(String[] args) {
var application = new SpringApplication(Lesson7.class);
application.run(args);
}

/**
* 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.
*/
public static boolean canVote(int age) {
throw new UnsupportedOperationException();
}

/**
* Compares two strings lexographically.
*
* @param value1 The first `String` to compare.
* @param value2 The second `String` to compare.
* @rerturn -1 if a is less than b, 1 if a is greater than b, and 0 otherwise.
*/
public static int compareStrings(String a, String b) {
// The distance will be a number less than 0 if string `a` is lexographically less than `b`, 1
// if it is greater, and 0 if the strings are equal.
int distance = Helpers.computeLexographicDistance(a, b);

// TODO(you): Finish this method.

return 0;
}

/** An instance of a GPA converter. */
private static final GpaToLetterGradeConverter gpaConverter = new GpaToLetterGradeConverter();

/**
* 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.).
*/
public static String convertGpaToLetterGrade(double gpa) {
return gpaConverter.convertToLetterGrade(gpa);
}

/**
* Computes the factorial of the given value of `n`.
*
* @param n The value for which to compute the factorial.
* @return The factorial of n.
*/
public static int computeFactorial(int n) {
return 0;
}

/**
* Adds all of the provided values and returns the sum.
*
* @param values The values to sum.
* @return The sum of all the values.
*/
public static double addNumbers(double[] values) {
return 0;
}

/**
* 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.
*/
public static int[] getFirstNFibonacciNumbers(int n) {
return null;
}

/**
* Finds a value in an array of values.
*
* @param values The values to search.
* @param The left most index to search.
* @param 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.
*/
public static int binarySearch(int[] values, int start, int end, int value) {

while (start <= end) {
int pivotIndex = (start + end) / 2;

if (values[pivotIndex] == value) {
return pivotIndex;
} else if (values[pivotIndex] > value) {
end = pivotIndex - 1;
} else {
start = pivotIndex + 1;
}
}

return -1;
}
}
@@ -0,0 +1,59 @@
package com.codedifferently.lesson7.gpa;

import com.codedifferently.lesson7.util.LinkedListNode;

/** An object that converts GPAs to their letter grade equivalent. */
public class GpaToLetterGradeConverter {

private LinkedListNode<GpaLetterGradeMapping> head;

public GpaToLetterGradeConverter() {
this.head = new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(0, 1, "F"));

var current = this.head;
current.next =
new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(1, 1.3, "D"));

current = current.next;
current.next =
new LinkedListNode<GpaLetterGradeMapping>(new GpaLetterGradeMapping(1.3, 1.7, "D+"));

// TODO(you): Finish configuring the linked list.
}

/**
* 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.).
*/
public String convertToLetterGrade(double gpa) throws IllegalArgumentException {
// Iterate through the list list starting at the head node and return the letter grade for the
// matching GPA range.
throw new UnsupportedOperationException();
}
}

/** An object that represents the mapping between a GPA range and a grade letter. */
class GpaLetterGradeMapping {
public double minGpaInclusive;
public double maxGpaExclusive;
public String gradeLetter;

public GpaLetterGradeMapping(double minGpaInclusive, double maxGpaExclusive, String gradeLetter) {
this.minGpaInclusive = minGpaInclusive;
this.maxGpaExclusive = maxGpaExclusive;
this.gradeLetter = gradeLetter;
}

public boolean includesGpa(double gpa) {
throw new UnsupportedOperationException();
}

public String getLetterGrade() {
throw new UnsupportedOperationException();
}
}
@@ -0,0 +1,28 @@
package com.codedifferently.lesson7.util;

public class Helpers {
/**
* Computes a score describing the lexographic distance between two strings. For two strings of
* equal length, the score will be the difference between the first differing character. In the
* case where either is a sub-string of the other, then the difference in length determines the
* score.
*
* @param a The first string to compare.
* @param b The second string to compare.
* @return A score representing the lexographic distance between two strings.
*/
public static int computeLexographicDistance(String a, String b) {
for (var i = 0; i < a.length(); ++i) {
if (a.charAt(i) == b.charAt(i)) {
continue;
}
return (int) a.charAt(i) - (int) b.charAt(i);
}

if (a.length() != b.length()) {
return a.length() - b.length();
}

return 0;
}
}
@@ -0,0 +1,14 @@
package com.codedifferently.lesson7.util;

/** A LinkedList node. */
public class LinkedListNode<T> {
/** The next node in a linked list. */
public LinkedListNode<T> next;

/** The data stored in this node. */
public T data;

public LinkedListNode(T data) {
this.data = data;
}
}