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 e8a0ed08148d6e027211fdbc70f6887b202d2238 Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Sat, 6 Jun 2026 00:03:13 -0400 Subject: [PATCH 2/3] Completed static exercises --- .../_13_staticmembers/StaticExercises.java | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/amigoscode/_2_developers/_13_staticmembers/StaticExercises.java b/src/main/java/com/amigoscode/_2_developers/_13_staticmembers/StaticExercises.java index 1cca4b2..ca60c2c 100644 --- a/src/main/java/com/amigoscode/_2_developers/_13_staticmembers/StaticExercises.java +++ b/src/main/java/com/amigoscode/_2_developers/_13_staticmembers/StaticExercises.java @@ -11,6 +11,7 @@ public class StaticExercises { // TODO: 1 - Create a private static int field called 'counter' initialized to 0. // This field is shared among ALL instances of StaticExercises. + private static int counter = 0; // An instance field for comparison (already provided) private String instanceName; @@ -18,56 +19,72 @@ public class StaticExercises { // TODO: 2 - Create a constructor that takes a String name parameter. // Assign the name to instanceName. // Increment the static counter by 1 each time a new instance is created. + public StaticExercises(String name) { + this.instanceName = name; + counter++; + } // TODO: 3 - Create a public static method: int getCount() // Returns the current value of counter. // Note: static methods can only access static fields, not instance fields. + public static int getCount() { + return counter; + } // TODO: 4 - Create a public static utility method: double celsiusToFahrenheit(double celsius) // Returns the temperature in Fahrenheit using the formula: (celsius * 9/5) + 32. // Utility methods are a common use case for static methods — they don't need // any instance state. + public static double celsiusToFahrenheit(double celsius) { + return (celsius * 9/5) + 32; + } // TODO: 5 - Create a public method (non-static): String getInfo() // Returns "Instance: , Total instances: " // This demonstrates that instance methods can access BOTH instance and static fields. // A static method could NOT access instanceName. + public String getInfo() { + return "Instance: " + instanceName + ", Total instances: " + getCount(); + } // TODO: 6 - Create a public static factory method: StaticExercises createDefault() // Returns a new StaticExercises instance with the name "Default". // Factory methods are static methods that create and return instances. // They are an alternative to constructors and can have descriptive names. + public static StaticExercises createDefault() { + return new StaticExercises("Default"); + } public static void main(String[] args) { // Uncomment the code below after completing all TODOs: - // System.out.println("=== Static Counter ==="); - // System.out.println("Count before creating instances: " + getCount()); + System.out.println("=== Static Counter ==="); + System.out.println("Count before creating instances: " + getCount()); - // StaticExercises obj1 = new StaticExercises("First"); - // StaticExercises obj2 = new StaticExercises("Second"); - // StaticExercises obj3 = new StaticExercises("Third"); + StaticExercises obj1 = new StaticExercises("First"); + StaticExercises obj2 = new StaticExercises("Second"); + StaticExercises obj3 = new StaticExercises("Third"); - // System.out.println("Count after creating 3 instances: " + getCount()); + System.out.println("Count after creating 3 instances: " + getCount()); - // System.out.println("\n=== Static Utility Method ==="); - // System.out.println("0°C = " + celsiusToFahrenheit(0) + "°F"); - // System.out.println("100°C = " + celsiusToFahrenheit(100) + "°F"); - // System.out.println("37°C = " + celsiusToFahrenheit(37) + "°F"); + System.out.println("\n=== Static Utility Method ==="); + System.out.println("0°C = " + celsiusToFahrenheit(0) + "°F"); + System.out.println("100°C = " + celsiusToFahrenheit(100) + "°F"); + System.out.println("37°C = " + celsiusToFahrenheit(37) + "°F"); - // System.out.println("\n=== Static vs Instance ==="); - // System.out.println(obj1.getInfo()); - // System.out.println(obj2.getInfo()); - // Note: getCount() is called on the class, getInfo() is called on an instance - // StaticExercises.getCount() works, but StaticExercises.getInfo() does NOT compile + System.out.println("\n=== Static vs Instance ==="); + System.out.println(obj1.getInfo()); + System.out.println(obj2.getInfo()); +// Note: getCount() is called on the class, getInfo() is called on an instance +// StaticExercises.getCount() works, but StaticExercises.getInfo() does NOT compile - // System.out.println("\n=== Static Factory Method ==="); - // StaticExercises defaultObj = StaticExercises.createDefault(); - // System.out.println(defaultObj.getInfo()); + System.out.println("\n=== Static Factory Method ==="); + StaticExercises defaultObj = StaticExercises.createDefault(); + System.out.println(defaultObj.getInfo()); } } From 50371e72a386eb2f3b429f792d609218f29442ef Mon Sep 17 00:00:00 2001 From: Jose De La Cruz <74112121+jose-a-dlc05@users.noreply.github.com> Date: Sat, 6 Jun 2026 00:04:24 -0400 Subject: [PATCH 3/3] Delete src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java --- .../_1_beginners/_1_thebasics/Variables.java | 43 ------------------- 1 file changed, 43 deletions(-) delete mode 100644 src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java 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 deleted file mode 100644 index 8402e0d..0000000 --- a/src/main/java/com/amigoscode/_1_beginners/_1_thebasics/Variables.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.amigoscode._1_beginners._1_thebasics; - -/** - * Exercise: Variables and Data Types - * - * Learn how to declare and use variables of different types in Java. - * Java is a statically-typed language, meaning every variable must have a declared type. - */ -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); - - } -}