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/3] 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 ca0d6b334f63cc38446fe853ac6c18ef4121b4a0 Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Tue, 2 Jun 2026 06:35:42 -0400 Subject: [PATCH 2/3] Completed MethodExercises, Operators and TypeCasting exercises --- .../_1_thebasics/MethodExercises.java | 44 +++++++++++++-- .../_1_beginners/_1_thebasics/Operators.java | 54 ++++++++++++++++++- .../_1_thebasics/TypeCasting.java | 34 +++++++++++- 3 files changed, 125 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/MethodExercises.java b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/MethodExercises.java index 359f885..9a003a2 100644 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/MethodExercises.java +++ b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/MethodExercises.java @@ -11,43 +11,81 @@ public class MethodExercises { // TODO: 1 - Create a method called greet that takes a String parameter 'name' // and prints "Hello, {name}!" // Hint: public static void greet(String name) { ... } - + public static void greet(String name) { + System.out.printf("Hello %s",name); + System.out.println(); + } // TODO: 2 - Create a method called add that takes two int parameters (a, b) // and returns their sum // Hint: public static int add(int a, int b) { ... } + public static int add(int a, int b) { + return a + b; + } // TODO: 3 - Create a method called isEven that takes an int parameter 'number' // and returns true if the number is even, false otherwise // Hint: Use the modulus operator (%) - + public static boolean isEven(int number) { + return number % 2 == 0; + } // TODO: 4 - Create a method called max that takes two int parameters (a, b) // and returns the larger of the two // Hint: Use an if statement or the ternary operator - + public static int max(int a, int b) { + return Math.max(a, b); + } // TODO: 5 - Create a method called factorial that takes an int parameter 'n' // and returns n! (n factorial) using a loop // Hint: 5! = 5 * 4 * 3 * 2 * 1 = 120. Use a long return type for larger values. + public static int factorial(int n) { + int factorialPlaceholder = 1; + for (int num = 1; num <= n; num++) { + factorialPlaceholder *= num; + } + return factorialPlaceholder; + } // TODO: 6 - Create two overloaded methods called multiply: // - One that takes 2 int parameters and returns their product // - One that takes 3 int parameters and returns their product // Overloading means having multiple methods with the same name but different parameters. + public static int multiply(int a, int b) { + return a * b; + } + + public static int multiply(int a, int b, int c) { + return a * b * c; + } public static void main(String[] args) { // TODO: 7 - Call all the methods above and print their results // - Call greet with your name + greet("Jose"); // - Call add with two numbers and print the result + int result = add(6, 7); + System.out.println(result); // - Call isEven with a number and print whether it is even + boolean isEvenResult = isEven(5); + System.out.println(isEvenResult); // - Call max with two numbers and print the larger one + int maxNumber = max(6, 9); + System.out.println(maxNumber); // - Call factorial with 5 and print the result + int factorialRes = factorial(7); + System.out.println(factorialRes); // - Call both multiply methods and print their results + int multiply1 = multiply(5, 5); + int multiply2 = multiply(5, 5, 5); + + System.out.println("multiply1 result: " + multiply1); + System.out.println("multiply2 result: " + multiply2); } } diff --git a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Operators.java b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Operators.java index 3dca8a0..aac5f65 100644 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Operators.java +++ b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Operators.java @@ -13,27 +13,65 @@ public static void main(String[] args) { // TODO: 1 - Use arithmetic operators (+, -, *, /) on two int variables and print the results // Declare two int variables (e.g., a = 10, b = 3) // Print the result of a + b, a - b, a * b, and a / b + System.out.println("TODO 1"); + int num1 = 10; + int num2 = 3; + System.out.println("Addition: " + (num1 + num2)); + System.out.println("Subtraction: " + (num1 - num2)); + System.out.println("Multiplication: " + (num1 * num2)); + System.out.println("Division: " + (num1 /+ num2)); + System.out.println(); // TODO: 2 - Use the modulus operator (%) to check if a number is even // Declare an int variable called number with any value. // Print the result of number % 2 // Print whether the number is even (result is 0) or odd (result is 1) - + System.out.println("TODO 2"); + System.out.println("------------------------"); + int variable = 78; + int isEven = variable % 2 == 0 ? 0 : 1; + System.out.println(isEven); // TODO: 3 - Use increment (++) and decrement (--) operators // Declare an int variable called counter, set it to 5 // Use counter++ and print the result, then use counter-- and print the result - + System.out.println("TODO 3"); + System.out.println("------------------------"); + int counter = 5; + counter++; + System.out.println(counter); + counter--; + System.out.println(counter); // TODO: 4 - Use compound assignment operators (+=, -=, *=) // Declare an int variable called score, set it to 10 // Use +=, -=, and *= on score, printing after each operation + System.out.println("TODO 4"); + System.out.println("------------------------"); + int score = 10; + score += 5; + System.out.println(score); + score -= 5; + System.out.println(score); + score *= 5; + System.out.println(score); + // TODO: 5 - Use comparison operators (==, !=, >, <, >=, <=) and print the boolean results // Declare two int variables (e.g., x = 5, y = 10) // Print the result of each comparison, e.g.: System.out.println("x == y: " + (x == y)); + System.out.println("TODO 5"); + System.out.println("------------------------"); + int x = 20; + int y = 40; + System.out.println("x == y: " + ( x == y)); + System.out.println("x >= y: " + (x >= y)); + System.out.println("x <= y: " + (x <= y)); + System.out.println("x > y: " + (x > y)); + System.out.println("x < y: " + (x < y)); + System.out.println("x != y: " + (x != y)); // TODO: 6 - Use logical operators (&&, ||, !) to combine conditions @@ -41,12 +79,24 @@ public static void main(String[] args) { // Print the result of: hasLicense && hasInsurance // Print the result of: hasLicense || hasInsurance // Print the result of: !hasLicense + System.out.println("TODO 6"); + System.out.println("------------------------"); + boolean hasLicense = true; + boolean hasInsurance = false; + System.out.println("hasLicense && hasInsurance: " + (hasLicense && hasInsurance)); + System.out.println("hasLicense || hasInsurance: " + (hasLicense || hasInsurance)); + System.out.println("!hasLicense: " + (!hasLicense)); // TODO: 7 - Use the ternary operator to assign "adult" or "minor" based on age // Declare an int variable called age with any value // Use the ternary operator: String status = (condition) ? "adult" : "minor"; // Print the status + System.out.println("TODO 6"); + System.out.println("------------------------"); + int age = 36; + String status = age >= 18 ? "adult" : "minor"; + System.out.println("Are you an adult?: " + status); } } diff --git a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java index a71db6c..ffe4660 100644 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java +++ b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java @@ -14,31 +14,61 @@ public static void main(String[] args) { // TODO: 1 - Widen an int to a double (implicit casting) // Declare an int variable with any value, then assign it to a double variable. // Print both variables to see the result. - + System.out.println("Widen an int to a double (implicit casting)"); + int number = 50; + double numberCastedDouble = number; + System.out.println("number: " + number); + System.out.println("numberDouble: " + numberCastedDouble); // TODO: 2 - Narrow a double to an int (explicit casting) // Declare a double variable (e.g., 9.78), then cast it to an int. // Print both variables to see what happens to the decimal part. - + System.out.println("---------------------------------------------"); + System.out.println("Narrow a double to an int (explicit casting)"); + double todoTwoDouble = 9.78; + int todoTwoInt = (int) todoTwoDouble; + System.out.println("todoTwoDouble: " + todoTwoDouble); + System.out.println("todoTwoInt: " + todoTwoInt); // TODO: 3 - Cast an int to a char to get the character it represents // Hint: int value 65 corresponds to 'A' in ASCII // Print the resulting char. + System.out.println("---------------------------------------------"); + System.out.println("Cast an int to a char to get the character it represents"); + int todoThreeInt = 65; + char todoThreeChar = (char) todoThreeInt; + System.out.println("todoThreeInt: " + todoThreeInt); + System.out.println("todoThreeChar: " + todoThreeChar); // TODO: 4 - Cast a char to an int to get its ASCII value // Hint: char 'Z' has an ASCII value of 90 // Print the resulting int. + System.out.println("---------------------------------------------"); + System.out.println("Cast a char to an int to get its ASCII value"); + char todoFourChar = 'Z'; + int todoFourInt = todoFourChar; + System.out.println("todoFourChar: " + todoFourChar); + System.out.println("todoFourInt: " + todoFourInt); + // TODO: 5 - Convert a String "42" to an int using Integer.parseInt() // Declare a String variable with the value "42", then parse it to an int. // Print the result. + System.out.println("---------------------------------------------"); + System.out.println("Convert a String \"42\" to an int using Integer.parseInt()"); + String todoFiveString = "42"; + System.out.println(Integer.parseInt(todoFiveString)); // TODO: 6 - Convert an int 42 to a String using String.valueOf() // Declare an int variable with the value 42, then convert it to a String. // Print the result. + System.out.println("---------------------------------------------"); + System.out.println("Convert an int 42 to a String using String.valueOf()"); + int todoSixInt = 42; + System.out.println(String.valueOf(todoSixInt)); } } From 4389f461df12d73e61a4e925fa9accc07b53e4d6 Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Tue, 2 Jun 2026 06:37:35 -0400 Subject: [PATCH 3/3] Modified todo6 in typecasting file --- .../com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java index ffe4660..c81c75e 100644 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java +++ b/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/TypeCasting.java @@ -68,7 +68,8 @@ public static void main(String[] args) { System.out.println("---------------------------------------------"); System.out.println("Convert an int 42 to a String using String.valueOf()"); int todoSixInt = 42; - System.out.println(String.valueOf(todoSixInt)); + String todoSixIntString = String.valueOf(todoSixInt); + System.out.println(todoSixIntString); } }