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

feat: adds Lesson 06 assignment content #177

Merged
merged 19 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions .github/workflows/check_lesson_06_pr.yml
@@ -0,0 +1,32 @@
name: Check Lesson 06 Pull Request

on:
pull_request:
branches: [ "main" ]
paths:
- "lesson_06/conditionals/**"

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 06 with Gradle Wrapper
working-directory: ./lesson_06/conditionals
run: ./gradlew check

5 changes: 5 additions & 0 deletions .github/workflows/check_push.yml
Expand Up @@ -9,6 +9,7 @@ on:
- "lesson_03/quiz/**"
- "lesson_04/expression/**"
- "lesson_05/types/**"
- "lesson_06/conditionals/**"

jobs:
build:
Expand Down Expand Up @@ -46,6 +47,10 @@ jobs:
working-directory: ./lesson_05/types
run: ./gradlew check

- name: Build Lesson 06 with Gradle Wrapper
working-directory: ./lesson_06/conditionals
run: ./gradlew assemble && ./gradlew spotlessCheck

- name: Build Shared Lib with Gradle Wrapper
working-directory: ./lib/java/codedifferently-instructional
run: ./gradlew check
Expand Down
6 changes: 3 additions & 3 deletions lesson_02/quiz/.settings/org.eclipse.buildship.core.prefs
@@ -1,11 +1,11 @@
arguments=--init-script /root/.local/share/nvim/mason/packages/jdtls/config_linux/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle
auto.sync=false
arguments=--init-script /var/folders/jd/13987k395q3_lnyhg9db_bc00000gn/T/d146c9752a26f79b52047fb6dc6ed385d064e120494f96f08ca63a317c41f94c.gradle --init-script /var/folders/jd/13987k395q3_lnyhg9db_bc00000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle
auto.sync=true
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/root/.sdkman/candidates/java/17-open
java.home=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
334 changes: 5 additions & 329 deletions lesson_03/quiz/lesson_03_quiz/.classpath

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions lesson_03/quiz/lesson_03_quiz/.project
Expand Up @@ -2,27 +2,29 @@
<projectDescription>
<name>lesson_03_quiz</name>
<comment></comment>
<projects/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments/>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments/>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<linkedResources/>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
<filteredResources>
<filter>
<id>1</id>
<name></name>
<type>30</type>
<name/>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
Expand Down
@@ -1,11 +1,11 @@
arguments=--init-script /Users/anthonymays/.local/share/nvim/mason/packages/jdtls/config_mac/org.eclipse.osgi/54/0/.cp/gradle/init/init.gradle
auto.sync=false
arguments=--init-script /home/vscode/.vscode-server/data/User/globalStorage/redhat.java/1.28.1/config_linux/org.eclipse.osgi/55/0/.cp/gradle/init/init.gradle --init-script /home/vscode/.vscode-server/data/User/globalStorage/redhat.java/1.28.1/config_linux/org.eclipse.osgi/55/0/.cp/gradle/protobuf/init.gradle
auto.sync=true
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home
java.home=/usr/local/sdkman/candidates/java/current
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
13 changes: 13 additions & 0 deletions lesson_06/README.md
@@ -0,0 +1,13 @@
# Lesson 06

## Homework

* Read CC 16, 19; PIE 8
* Complete [Conditionals and Loops](#choosing-the-right-data-types) exercise.

## Conditionals and Loops

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/
9 changes: 9 additions & 0 deletions lesson_06/conditionals/.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_06/conditionals/.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_06/conditionals/conditionals_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,112 @@
package com.codedifferently.lesson6;

import com.codedifferently.lesson6.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 Lesson6 {

public static void main(String[] args) {
var application = new SpringApplication(Lesson6.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) {
return false;
}

/**
* 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;
}

/**
* 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 "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.
*/
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) {
if (end < start) {
//
return -1;
}

int pivotIndex = (start + end) / 2; // The index in the middle of the array.

// 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;
}
}
@@ -0,0 +1,28 @@
package com.codedifferently.lesson6.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;
}
}