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 e952ee50e5fae1acd8f02cd9216f29dbfdf64538 Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Fri, 5 Jun 2026 12:53:31 -0400 Subject: [PATCH 2/3] Completed classes and objects --- .../_1_beginners/_1_thebasics/Variables.java | 43 --------- .../_12_classes/ClassesAndObjects.java | 87 +++++++++++++------ 2 files changed, 62 insertions(+), 68 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); - - } -} diff --git a/src/main/java/com/amigoscode/_2_developers/_12_classes/ClassesAndObjects.java b/src/main/java/com/amigoscode/_2_developers/_12_classes/ClassesAndObjects.java index 12a7951..c919fc9 100644 --- a/src/main/java/com/amigoscode/_2_developers/_12_classes/ClassesAndObjects.java +++ b/src/main/java/com/amigoscode/_2_developers/_12_classes/ClassesAndObjects.java @@ -4,7 +4,7 @@ /** * Classes and Objects Exercises - * + *

* Practice creating classes with fields, constructors, and methods. * Learn about constructor chaining, toString(), and equals(). */ @@ -13,30 +13,57 @@ public class ClassesAndObjects { // TODO: 1 - Create a static inner class called Person with: // - A private String field 'name' // - A private int field 'age' - - - // TODO: 2 - Add a constructor to Person that takes String name and int age, - // and assigns them to the fields. - - - // TODO: 3 - Add a no-args constructor to Person that sets name to "Unknown" - // and age to 0. Use constructor chaining — call the other constructor - // using this("Unknown", 0) instead of setting fields directly. - // (See TODO 7 for more on constructor chaining.) - - - // TODO: 4 - Add a toString() method to Person that returns: - // "Person{name='', age=}" - // Annotate with @Override. - - - // TODO: 5 - Add an equals() method to Person that: - // - Returns true if the other object is a Person with the same name and age - // - Handles null and different types correctly - // - Annotate with @Override - // Hint: use instanceof, then cast and compare fields. - // Also override hashCode() using Objects.hash(name, age). - + public static class Person { + private String name; + private int age; + + // TODO: 2 - Add a constructor to Person that takes String name and int age, + // and assigns them to the fields. + public Person(String name, int age) { + this.name = name; + this.age = age; + } + + // TODO: 3 - Add a no-args constructor to Person that sets name to "Unknown" + // and age to 0. Use constructor chaining — call the other constructor + // using this("Unknown", 0) instead of setting fields directly. + // (See TODO 7 for more on constructor chaining.) + public Person() { + this("Unknown", 0); + } + // TODO: 4 - Add a toString() method to Person that returns: + // "Person{name='', age=}" + // Annotate with @Override. + + @Override + public String toString() { + return "Person{" + + "name='" + name + '\'' + + ", age=" + age + + '}'; + } + + + // TODO: 5 - Add an equals() method to Person that: + // - Returns true if the other object is a Person with the same name and age + // - Handles null and different types correctly + // - Annotate with @Override + // Hint: use instanceof, then cast and compare fields. + // Also override hashCode() using Objects.hash(name, age). + + @Override + public boolean equals(Object o) { + if(this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return age == person.age && Objects.equals(name, person.name); + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } + } public static void main(String[] args) { // TODO: 6 - Create at least three Person objects: @@ -47,7 +74,16 @@ public static void main(String[] args) { // Test equals(): compare person1 with person3 (should be true), // and person1 with person2 (should be false). // Print the comparison results. + Person alice = new Person("Alice", 30); + Person unknown = new Person(); + Person aliceDoppelganger = new Person("Alice", 30); + + System.out.println(alice); + System.out.println(unknown); + System.out.println(aliceDoppelganger); + System.out.println(alice.equals(aliceDoppelganger)); + System.out.println(alice.equals(unknown)); // TODO: 7 - Demonstrate constructor chaining with this(): // Add a comment explaining what constructor chaining is: @@ -55,6 +91,7 @@ public static void main(String[] args) { // it avoids duplicating initialization logic. // The no-args constructor you created in TODO 3 already demonstrates this. // Print: "No-args person: " + the no-args person to show the defaults. + System.out.println("No-args person: " + unknown); } } From f93d1a5f9e27f56fc2600dc262c844b1317a6ccf Mon Sep 17 00:00:00 2001 From: Jose De La Cruz Date: Fri, 5 Jun 2026 19:25:46 -0400 Subject: [PATCH 3/3] Completed enum exercise --- .../_12_classes/EnumExercises.java | 28 ++++++++++++++++++- .../_2_developers/_12_classes/Priority.java | 17 +++++++++++ .../_2_developers/_12_classes/Season.java | 18 ++++++++++++ 3 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/amigoscode/_2_developers/_12_classes/Priority.java create mode 100644 src/main/java/com/amigoscode/_2_developers/_12_classes/Season.java diff --git a/src/main/java/com/amigoscode/_2_developers/_12_classes/EnumExercises.java b/src/main/java/com/amigoscode/_2_developers/_12_classes/EnumExercises.java index 37601fa..a632ecb 100644 --- a/src/main/java/com/amigoscode/_2_developers/_12_classes/EnumExercises.java +++ b/src/main/java/com/amigoscode/_2_developers/_12_classes/EnumExercises.java @@ -1,8 +1,10 @@ package com.amigoscode._2_developers._12_classes; +import java.util.Arrays; + /** * Enum Exercises - * + *

* Practice creating and using enums in Java. Enums are special classes that * represent a fixed set of constants. They can have fields, constructors, * and methods just like regular classes. @@ -42,6 +44,19 @@ public static void main(String[] args) { // For each season, print a message like "Spring: Flowers bloom" // using the getDescription() method. // Test with Season.SUMMER. + Season season = Season.WINTER; + + switch (season) { + case WINTER: + case FALL: + case SUMMER: + case SPRING: + System.out.println(season.getDescription()); + break; + default: + System.out.println("Invalid Season"); + break; + } System.out.println("\n=== Iterate Over Enum Values ==="); @@ -49,6 +64,17 @@ public static void main(String[] args) { // Loop through them and print each one with its description and ordinal. // Example output: "0: SPRING - Flowers bloom" // Also iterate over Priority.values() and print each with its level. + Season[] seasons = Season.values(); + for(int i = 0; i < seasons.length; i++) { + System.out.println(i + ": " + seasons[i] + " - " + seasons[i].getDescription()); + } + + System.out.println("============"); + + Priority[] priorities = Priority.values(); + for(int i = 0; i < priorities.length; i++) { + System.out.println(i + ": " + priorities[i] + " - " + priorities[i].getLevel()); + } } } diff --git a/src/main/java/com/amigoscode/_2_developers/_12_classes/Priority.java b/src/main/java/com/amigoscode/_2_developers/_12_classes/Priority.java new file mode 100644 index 0000000..3960095 --- /dev/null +++ b/src/main/java/com/amigoscode/_2_developers/_12_classes/Priority.java @@ -0,0 +1,17 @@ +package com.amigoscode._2_developers._12_classes; + +public enum Priority { + LOW(1), + MEDIUM(2), + HIGH(3); + + private final int level; + + private Priority(int level) { + this.level = level; + } + + public int getLevel() { + return level; + } +} diff --git a/src/main/java/com/amigoscode/_2_developers/_12_classes/Season.java b/src/main/java/com/amigoscode/_2_developers/_12_classes/Season.java new file mode 100644 index 0000000..9856ad6 --- /dev/null +++ b/src/main/java/com/amigoscode/_2_developers/_12_classes/Season.java @@ -0,0 +1,18 @@ +package com.amigoscode._2_developers._12_classes; + +public enum Season { + WINTER("Snow falls"), + SUMMER("Sun shines"), + SPRING("Flowers bloom"), + FALL("Leaves fall"); + + private final String description; + + private Season(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } +}