Skip to content

Commit 4fb3601

Browse files
authored
feat: adds lesson_14 homework and lesson_15 pre-work (#445)
* feat: adds lesson_14 homework and lesson_15 pre-work Signed-off-by: Anthony D. Mays <[email protected]> * chore: whoops Signed-off-by: Anthony D. Mays <[email protected]> * chore: added the file back Signed-off-by: Anthony D. Mays <[email protected]> * chore: whoops again Signed-off-by: Anthony D. Mays <[email protected]> * chore: restoring the file for demo purposes Signed-off-by: Anthony D. Mays <[email protected]> --------- Signed-off-by: Anthony D. Mays <[email protected]>
1 parent abb394d commit 4fb3601

File tree

19 files changed

+701
-1
lines changed

19 files changed

+701
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Check Lesson 14 Java Pull Request
2+
3+
on:
4+
pull_request:
5+
branches: [ "main" ]
6+
paths:
7+
- "lesson_14/exceptions/**"
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
permissions:
14+
contents: read
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up JDK
20+
uses: actions/setup-java@v4
21+
with:
22+
java-version: '21'
23+
distribution: 'temurin'
24+
25+
- name: Build Lesson 13 with Java
26+
working-directory: ./lesson_14/exceptions
27+
run: ./gradlew check

lesson_14/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ Please review the following resources before lecture:
99

1010
## Homework
1111

12-
- TODO(anthonydmays): Add some details when you get a chance.
12+
- [ ] Complete [Exception Handling](#exception-handling) assignment.
13+
- [ ] Do pre-work for [lesson 15](/lesson_15/).
14+
15+
### Exception Handling
16+
17+
For this assignment, you will update existing code to add exceptions for unsupported operations in an e-commerce system.
18+
19+
To complete this assignment, [use the tests][test-link] to understand what you need to implement in order to get the tests to pass.
20+
21+
[test-link]: ./exceptions/exceptions_app/src/test/java/com/codedifferently/lesson14/ecommerce/EcommerceSystemTest.java

lesson_14/exceptions/.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# https://help.github.com/articles/dealing-with-line-endings/
3+
#
4+
# Linux start script should use lf
5+
/gradlew text eol=lf
6+
7+
# These are Windows script files and should use crlf
8+
*.bat text eol=crlf
9+

lesson_14/exceptions/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Ignore Gradle project-specific cache directory
2+
.gradle
3+
4+
# Ignore Gradle build output directory
5+
build
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
plugins {
2+
// Apply the application plugin to add support for building a CLI application in Java.
3+
application
4+
eclipse
5+
id("com.diffplug.spotless") version "6.25.0"
6+
id("org.springframework.boot") version "3.4.0"
7+
id("com.adarshr.test-logger") version "4.0.0"
8+
}
9+
10+
apply(plugin = "io.spring.dependency-management")
11+
12+
repositories {
13+
// Use Maven Central for resolving dependencies.
14+
mavenCentral()
15+
}
16+
17+
dependencies {
18+
// Use JUnit Jupiter for testing.
19+
testImplementation("com.codedifferently.instructional:instructional-lib")
20+
testImplementation("org.junit.jupiter:junit-jupiter:5.11.3")
21+
testImplementation("org.springframework.boot:spring-boot-starter-test")
22+
testImplementation("org.assertj:assertj-core:3.26.3")
23+
testImplementation("at.favre.lib:bcrypt:0.10.2")
24+
25+
// This dependency is used by the application.
26+
implementation("com.codedifferently.instructional:instructional-lib")
27+
implementation("com.google.guava:guava:33.3.1-jre")
28+
implementation("com.google.code.gson:gson:2.11.0")
29+
implementation("org.projectlombok:lombok:1.18.30")
30+
implementation("org.springframework.boot:spring-boot-starter")
31+
}
32+
33+
application {
34+
// Define the main class for the application.
35+
mainClass.set("com.codedifferently.lesson14.Lesson14")
36+
}
37+
38+
tasks.named<Test>("test") {
39+
// Use JUnit Platform for unit tests.
40+
useJUnitPlatform()
41+
}
42+
43+
44+
configure<com.diffplug.gradle.spotless.SpotlessExtension> {
45+
46+
format("misc", {
47+
// define the files to apply `misc` to
48+
target("*.gradle", ".gitattributes", ".gitignore")
49+
50+
// define the steps to apply to those files
51+
trimTrailingWhitespace()
52+
indentWithTabs() // or spaces. Takes an integer argument if you don't like 4
53+
endWithNewline()
54+
})
55+
56+
java {
57+
// don't need to set target, it is inferred from java
58+
59+
// apply a specific flavor of google-java-format
60+
googleJavaFormat()
61+
// fix formatting of type annotations
62+
formatAnnotations()
63+
}
64+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.codedifferently.lesson14;
2+
3+
public class Lesson14 {
4+
5+
public static void main(String[] args) {
6+
System.out.println("Hello World");
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.codedifferently.lesson14.ecommerce;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import java.util.UUID;
6+
7+
public class EcommerceSystem {
8+
private Map<String, Product> products;
9+
private Map<String, Order> orders;
10+
11+
public EcommerceSystem() {
12+
products = new HashMap<>();
13+
orders = new HashMap<>();
14+
}
15+
16+
public void addProduct(String productId, String name) {
17+
products.put(productId, new Product(productId, name));
18+
}
19+
20+
public String placeOrder(String productId, int quantity) {
21+
Product product = products.get(productId);
22+
String orderId = UUID.randomUUID().toString();
23+
orders.put(orderId, new Order(orderId, product, quantity));
24+
return orderId;
25+
}
26+
27+
public void cancelOrder(String orderId) {
28+
orders.remove(orderId);
29+
}
30+
31+
public String checkOrderStatus(String orderId) {
32+
Order order = orders.get(orderId);
33+
return "Order ID: "
34+
+ orderId
35+
+ ", Product: "
36+
+ order.getProduct().getName()
37+
+ ", Quantity: "
38+
+ order.getQuantity();
39+
}
40+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.codedifferently.lesson14.ecommerce;
2+
3+
public class Order {
4+
private String orderId;
5+
private Product product;
6+
private int quantity;
7+
8+
public Order(String orderId, Product product, int quantity) {
9+
this.orderId = orderId;
10+
this.product = product;
11+
this.quantity = quantity;
12+
}
13+
14+
public String getOrderId() {
15+
return orderId;
16+
}
17+
18+
public Product getProduct() {
19+
return product;
20+
}
21+
22+
public int getQuantity() {
23+
return quantity;
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*
2+
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
3+
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
4+
*/
5+
6+
package com.codedifferently.lesson14.ecommerce;
7+
8+
class OrderNotFoundException {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.codedifferently.lesson14.ecommerce;
2+
3+
public class Product {
4+
private String productId;
5+
private String name;
6+
7+
public Product(String productId, String name) {
8+
this.productId = productId;
9+
this.name = name;
10+
}
11+
12+
public String getProductId() {
13+
return productId;
14+
}
15+
16+
public String getName() {
17+
return name;
18+
}
19+
}

0 commit comments

Comments
 (0)