From b2ff0d101454f3e9d37fb840489d7d108608b2ec Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Thu, 28 May 2026 14:05:35 -0400 Subject: [PATCH 1/2] Completion of Variables.java --- .../_1_beginners/_1_thebasics/Variables.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java index 3d2ef3b..8402e0d 100644 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java +++ b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java @@ -11,27 +11,33 @@ public class Variables { public static void main(String[] args) { // TODO: 1 - Declare an int variable called age and assign it the value 25 - + int age = 25; // TODO: 2 - Declare a double variable called price and assign it the value 9.99 - + double price = 9.99; // TODO: 3 - Declare a boolean variable called isJavaFun and assign it the value true - + boolean isJavaFun = true; // TODO: 4 - Declare a String variable called name and assign it your name - + String name = "Jose"; // TODO: 5 - Declare a char variable called grade and assign it the value 'A' - + char grade = 'A'; // TODO: 6 - Print all the variables above using System.out.println // Hint: You can print each variable on its own line, e.g.: // System.out.println("Age: " + age); - + System.out.println("Age: " + age); + System.out.println("Price: " + price); + System.out.println("isJavaFun: " + isJavaFun); + System.out.println("Name: " + name); + System.out.println("Grade: " + grade); // TODO: 7 - Declare a final (constant) variable called MAX_SCORE, set it to 100, and print it // Hint: Use the 'final' keyword before the type to make a constant + final int MAX_SCORE = 100; + System.out.println("MAX_SCORE: " + MAX_SCORE); } } From 4afe5ff496cc23d6534325d3214087436e270f28 Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Wed, 3 Jun 2026 11:49:10 -0400 Subject: [PATCH 2/2] Completed big_decimal --- .../_8_bigdecimal/BigDecimalExercises.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/amigoscode/_2_developers/_8_bigdecimal/BigDecimalExercises.java b/src/main/java/com/amigoscode/_2_developers/_8_bigdecimal/BigDecimalExercises.java index 5a7575f..e01030c 100644 --- a/src/main/java/com/amigoscode/_2_developers/_8_bigdecimal/BigDecimalExercises.java +++ b/src/main/java/com/amigoscode/_2_developers/_8_bigdecimal/BigDecimalExercises.java @@ -23,7 +23,7 @@ public static BigDecimal createFromString(String value) { // TODO: 1 - Create and return a BigDecimal using new BigDecimal(value). // The String constructor preserves the exact decimal value. // NEVER use new BigDecimal(0.1) — see TODO 6 for why. - return null; + return new BigDecimal(value); } /** @@ -36,7 +36,7 @@ public static BigDecimal createFromString(String value) { public static BigDecimal addValues(BigDecimal a, BigDecimal b) { // TODO: 2 - Use the add() method to add a and b. Return the result. // Remember: BigDecimal is immutable, so add() returns a NEW BigDecimal. - return null; + return a.add(b); } /** @@ -48,7 +48,7 @@ public static BigDecimal addValues(BigDecimal a, BigDecimal b) { */ public static BigDecimal multiplyValues(BigDecimal a, BigDecimal b) { // TODO: 3 - Use the multiply() method to multiply a and b. Return the result. - return null; + return a.multiply(b); } /** @@ -63,7 +63,7 @@ public static BigDecimal divideValues(BigDecimal a, BigDecimal b, int scale) { // TODO: 4 - Use a.divide(b, scale, RoundingMode.HALF_UP) to divide. // You MUST specify a rounding mode for division, otherwise you may get // an ArithmeticException for non-terminating decimals (like 1/3). - return null; + return a.divide(b, scale, RoundingMode.HALF_UP); } /** @@ -80,7 +80,7 @@ public static int compareValues(BigDecimal a, BigDecimal b) { // TODO: 5 - Use a.compareTo(b) to compare the two values. // Return the result (which will be -1, 0, or 1). // Do NOT use equals() for numeric comparison! - return 0; + return a.compareTo(b); } /** @@ -94,6 +94,12 @@ public static void demonstrateDoubleProblem() { // Print both values. Notice that fromDouble is NOT exactly 0.1! // It will show something like 0.1000000000000000055511151231257827021181583404541015625 // Print a message explaining why the String constructor should be preferred. + System.out.println("The string constructor should be preferred because passing in a double\n " + + "causes the 0.1 to actually be 0.1000000000000000055511151231257827021181583404541015625 because\n" + + "it is essentially a floating point number based on binary fractions (base 2).\n" + + "Passing it through the BigDecimal constructor will allow it to do it's job exactly as it's meant to\n" + + "which is storing that exact long number into memory."); + }