From e11b182662e84e053c98280d9c07cf793807dc49 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:52:46 -0700 Subject: [PATCH 01/60] float datatype --- src/NumberPractice.java | 2 ++ toRefresh.md | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index bbec2fe..c7e6dfb 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -1,6 +1,8 @@ public class NumberPractice { public static void main(String args[]) { // Create a float with a negative value and assign it to a variable + float num = -2.345f; + System.out.println(num); // Create an int with a positive value and assign it to a variable diff --git a/toRefresh.md b/toRefresh.md index 163dcab..83db772 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -2,4 +2,4 @@ As you work through this exercise, write down anything that you needed to look up or struggled to remember here. It can be just a word or two (e.g. "joining strings"). You can use this as a guide of what to make extra sure you're refreshed on before exams and interviews. -- \ No newline at end of file +- float datatype \ No newline at end of file From e93e6a00b2e58c6ff486032ccfa5e31d60bd35d1 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Tue, 30 Sep 2025 22:55:31 -0700 Subject: [PATCH 02/60] Positive int number --- src/NumberPractice.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index c7e6dfb..6f47e8a 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -5,6 +5,8 @@ public static void main(String args[]) { System.out.println(num); // Create an int with a positive value and assign it to a variable + int positiveNum = 5; + System.out.println(positiveNum); // Use the modulo % operator to find the remainder when the int is divided by 3 From 9eb9164d2c289c60f93534fd8cc3883ed845a057 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Tue, 30 Sep 2025 23:05:33 -0700 Subject: [PATCH 03/60] Find remainder using modulo --- src/NumberPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index 6f47e8a..c55bde5 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -9,6 +9,7 @@ public static void main(String args[]) { System.out.println(positiveNum); // Use the modulo % operator to find the remainder when the int is divided by 3 + System.out.println(positiveNum % 3); // Use the modulo % operator to determine whether the number is even // (A number is even if it has a remainder of zero when divided by 2) From 477b58eb3b278e31977e643f11b98b6142301880 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Tue, 30 Sep 2025 23:12:00 -0700 Subject: [PATCH 04/60] Determine whether the num is even or odd --- src/NumberPractice.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index c55bde5..621fda5 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -15,6 +15,11 @@ public static void main(String args[]) { // (A number is even if it has a remainder of zero when divided by 2) // Use an if-else to print "Even" if the number is even and "Odd" // if the number is odd. + if (positiveNum % 2 == 0){ + System.out.println("Even"); + } else { + System.out.println("Odd"); + } // Divide the number by another number using integer division From 4d908f21f3d9e71c184c5e8eb5a0455cf5b57570 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Tue, 30 Sep 2025 23:14:18 -0700 Subject: [PATCH 05/60] Divide num by another number --- src/NumberPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index 621fda5..74acb75 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -22,6 +22,7 @@ public static void main(String args[]) { } // Divide the number by another number using integer division + System.out.println(positiveNum / 5); /* * Reminder! From 6844f3418456c08a77e59832277916b0452d5e65 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 09:16:44 -0700 Subject: [PATCH 06/60] Created an empty ArrayList of Strings --- src/ListPractice.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index f4de8e7..96fffc0 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -1,8 +1,10 @@ -public class ListPractice { +import java.util.*; +public class ListPractice { public static void main(String[] args) { // Create an empty ArrayList of Strings and assign it to a variable of type List + List list = new ArrayList<>(); // Add 3 elements to the list (OK to do one-by-one) From 76c31c5403f5d957d13492f507944214574b7185 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:47:30 -0700 Subject: [PATCH 07/60] Added 3 elements to the list and updated toRefresh --- src/ListPractice.java | 4 ++++ toRefresh.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index 96fffc0..383b89f 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -7,6 +7,10 @@ public static void main(String[] args) { List list = new ArrayList<>(); // Add 3 elements to the list (OK to do one-by-one) + list.add("Hi"); + list.add("Hello"); + list.add("Good morning"); + System.out.println(list); // Print the element at index 1 diff --git a/toRefresh.md b/toRefresh.md index 83db772..db1f274 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -2,4 +2,5 @@ As you work through this exercise, write down anything that you needed to look up or struggled to remember here. It can be just a word or two (e.g. "joining strings"). You can use this as a guide of what to make extra sure you're refreshed on before exams and interviews. -- float datatype \ No newline at end of file +- float datatype +- Syntax to create empty ArrayList/List \ No newline at end of file From 97094ec1449a58e87939bb6cef35ea553603c56f Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 10:55:20 -0700 Subject: [PATCH 08/60] Print element at index, updated toRefresh --- src/ListPractice.java | 1 + toRefresh.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index 383b89f..3de95ff 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -13,6 +13,7 @@ public static void main(String[] args) { System.out.println(list); // Print the element at index 1 + System.out.println(list.get(1)); // Replace the element at index 1 with a new value // (Do not insert a new value. The length of the list should not change) diff --git a/toRefresh.md b/toRefresh.md index db1f274..57c8611 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -3,4 +3,5 @@ As you work through this exercise, write down anything that you needed to look up or struggled to remember here. It can be just a word or two (e.g. "joining strings"). You can use this as a guide of what to make extra sure you're refreshed on before exams and interviews. - float datatype -- Syntax to create empty ArrayList/List \ No newline at end of file +- Syntax to create empty ArrayList/List +- .get() to find element at index \ No newline at end of file From e3bb283acd4045e2762658a976b75f8a9eaeb906 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:06:25 -0700 Subject: [PATCH 09/60] replaced element at index, updated toRefresh --- src/ListPractice.java | 2 ++ toRefresh.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index 3de95ff..080cd83 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -17,6 +17,8 @@ public static void main(String[] args) { // Replace the element at index 1 with a new value // (Do not insert a new value. The length of the list should not change) + list.set(1,"Hey"); + System.out.println(list); // Insert a new element at index 0 (the length of the list will change) diff --git a/toRefresh.md b/toRefresh.md index 57c8611..d9601a4 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -4,4 +4,5 @@ As you work through this exercise, write down anything that you needed to look u - float datatype - Syntax to create empty ArrayList/List -- .get() to find element at index \ No newline at end of file +- .get() to find element at index +- .set() to replace an element at index \ No newline at end of file From a245bb3bb34d4ce6e99f0a7c94ebf7c85c86dc56 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:11:56 -0700 Subject: [PATCH 10/60] Inserted new element at index --- src/ListPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ListPractice.java b/src/ListPractice.java index 080cd83..f0df3c2 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -21,8 +21,11 @@ public static void main(String[] args) { System.out.println(list); // Insert a new element at index 0 (the length of the list will change) + list.add(0, "Good night"); + System.out.println(list); // Check whether the list contains a certain string + // Iterate over the list using a traditional for-loop. // Print each index and value on a separate line From 47cbc1ffbb5237dbdb74b456c44185eb773610bd Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:13:47 -0700 Subject: [PATCH 11/60] Checked list for certain string --- src/ListPractice.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index f0df3c2..c5fc13c 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -25,7 +25,7 @@ public static void main(String[] args) { System.out.println(list); // Check whether the list contains a certain string - + System.out.println(list.contains("Hey")); // Iterate over the list using a traditional for-loop. // Print each index and value on a separate line From e265ccb55532295b046561548a50f9a1a2199c9d Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:26:51 -0700 Subject: [PATCH 12/60] Using traditional for-loop to iterate list and print index-value, updated toRefresh --- src/ListPractice.java | 4 ++++ toRefresh.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index c5fc13c..fee4f94 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -29,6 +29,10 @@ public static void main(String[] args) { // Iterate over the list using a traditional for-loop. // Print each index and value on a separate line + for (int i = 0; i < list.size(); i++){ + String word = list.get(i); + System.out.println("Value at index " + i + ": " + word); + } // Sort the list using the Collections library diff --git a/toRefresh.md b/toRefresh.md index d9601a4..96ce095 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -5,4 +5,5 @@ As you work through this exercise, write down anything that you needed to look u - float datatype - Syntax to create empty ArrayList/List - .get() to find element at index -- .set() to replace an element at index \ No newline at end of file +- .set() to replace an element at index +- .size() to get number of elements in list \ No newline at end of file From 7a5207163dc339ff78035cab74957bc5766a8c6a Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:30:09 -0700 Subject: [PATCH 13/60] Used the Collections library, updated toRefresh --- src/ListPractice.java | 2 ++ toRefresh.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index fee4f94..9a92167 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -35,6 +35,8 @@ public static void main(String[] args) { } // Sort the list using the Collections library + Collections.sort(list); + System.out.println(list); // Iterate over the list using a for-each loop // Print each value on a second line diff --git a/toRefresh.md b/toRefresh.md index 96ce095..47020a0 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -6,4 +6,5 @@ As you work through this exercise, write down anything that you needed to look u - Syntax to create empty ArrayList/List - .get() to find element at index - .set() to replace an element at index -- .size() to get number of elements in list \ No newline at end of file +- .size() to get number of elements in list +- Collections.sort() \ No newline at end of file From 249b9d4a2b64da00b32fa830bbe3c1ea0528a029 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:34:54 -0700 Subject: [PATCH 14/60] Used for-each loop to print each value --- src/ListPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ListPractice.java b/src/ListPractice.java index 9a92167..5613f5b 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -40,6 +40,9 @@ public static void main(String[] args) { // Iterate over the list using a for-each loop // Print each value on a second line + for (String str : list){ + System.out.println(str); + } /* * Usage tip! From 701eb23f472132907ac4b379000cad950d2567f6 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:47:41 -0700 Subject: [PATCH 15/60] Created array of Strings, update toRefresh --- src/ArrayPractice.java | 2 ++ toRefresh.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index bc58c83..506509c 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -1,6 +1,8 @@ + public class ArrayPractice { public static void main(String[] args) { // Create an array of Strings of size 4 + String[] array = new String[4]; // Set the value of the array at each index to be a different String // It's OK to do this one-by-one diff --git a/toRefresh.md b/toRefresh.md index 47020a0..db6e7f8 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -7,4 +7,5 @@ As you work through this exercise, write down anything that you needed to look u - .get() to find element at index - .set() to replace an element at index - .size() to get number of elements in list -- Collections.sort() \ No newline at end of file +- Collections.sort() +- Arrays vs Lists \ No newline at end of file From f3761192810da3b0664af1f5c801276aa69ff9a5 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:57:20 -0700 Subject: [PATCH 16/60] Added values to each index in array --- src/ArrayPractice.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index 506509c..961506c 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -6,6 +6,14 @@ public static void main(String[] args) { // Set the value of the array at each index to be a different String // It's OK to do this one-by-one + array[0] = "Noodles"; + array[1] = "Rice"; + array[2] = "Pasta"; + array[3] = "Bread"; + System.out.println(array[0]); + System.out.println(array[1]); + System.out.println(array[2]); + System.out.println(array[3]); // Get the value of the array at index 2 From be3dab2d51e972939222680a243c0e830c94e8f9 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 11:59:42 -0700 Subject: [PATCH 17/60] Get value at index 2 --- src/ArrayPractice.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index 961506c..ac7ec61 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -10,12 +10,13 @@ public static void main(String[] args) { array[1] = "Rice"; array[2] = "Pasta"; array[3] = "Bread"; - System.out.println(array[0]); - System.out.println(array[1]); - System.out.println(array[2]); - System.out.println(array[3]); + // System.out.println(array[0]); + // System.out.println(array[1]); + // System.out.println(array[2]); + // System.out.println(array[3]); // Get the value of the array at index 2 + System.out.println(array[2]); // Get the length of the array From 827ed3d350b593ed0c26ceea6c8943c53fe3af11 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:01:41 -0700 Subject: [PATCH 18/60] Find the length of the array --- src/ArrayPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index ac7ec61..6fb13f1 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -19,6 +19,7 @@ public static void main(String[] args) { System.out.println(array[2]); // Get the length of the array + System.out.println(array.length); // Iterate over the array using a traditional for loop and print out each item From c5fb9c353c18f9117f1455c452a82d0c5d0a8d9b Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:06:21 -0700 Subject: [PATCH 19/60] Traditional for-loop to print each item, updated toRefresh --- src/ArrayPractice.java | 3 +++ toRefresh.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index 6fb13f1..7254eae 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -22,6 +22,9 @@ public static void main(String[] args) { System.out.println(array.length); // Iterate over the array using a traditional for loop and print out each item + for (int i = 0; i < array.length; i++){ + System.out.println(array[i]); + } // Iterate over the array using a for-each loop and print out each item diff --git a/toRefresh.md b/toRefresh.md index db6e7f8..7f3b895 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -8,4 +8,5 @@ As you work through this exercise, write down anything that you needed to look u - .set() to replace an element at index - .size() to get number of elements in list - Collections.sort() -- Arrays vs Lists \ No newline at end of file +- Arrays vs Lists +- traditional for-loop for arrays \ No newline at end of file From 1106f23eac154a500968e847e1ee961e80115599 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:09:14 -0700 Subject: [PATCH 20/60] Used for-each loop to print out items --- src/ArrayPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index 7254eae..e570394 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -27,6 +27,9 @@ public static void main(String[] args) { } // Iterate over the array using a for-each loop and print out each item + for (String str : array) { + System.out.println(str); + } /* * Reminder! From 9365bebcc5e70fb20910b15dd4475ce29cb8f7d1 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:12:41 -0700 Subject: [PATCH 21/60] Assigned String to variable --- src/StringPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index 8d87617..286f30b 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -1,6 +1,7 @@ public class StringPractice { public static void main(String[] args) { // Create a string with at least 5 characters and assign it to a variable + String word = "October"; // Find the length of the string From 2ee4e8eb979b1f901a8923b701ab60a29a912073 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:15:13 -0700 Subject: [PATCH 22/60] Find length of the string --- src/StringPractice.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index 286f30b..6bef0b4 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -2,8 +2,10 @@ public class StringPractice { public static void main(String[] args) { // Create a string with at least 5 characters and assign it to a variable String word = "October"; + System.out.println(word); // Find the length of the string + System.out.println(word.length()); // Concatenate (add) two strings together and reassign the result From 8f680c1d9cfabf3bf715239c811043a7d50a3ba7 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:18:32 -0700 Subject: [PATCH 23/60] Concatenate two strings together --- src/StringPractice.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index 6bef0b4..42184f7 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -8,7 +8,10 @@ public static void main(String[] args) { System.out.println(word.length()); // Concatenate (add) two strings together and reassign the result - + String word2 = "November"; + String newWord = word + word2; + System.out.println(newWord); + // Find the value of the character at index 3 // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) From 4f3786367b26321bb35d4f33eaa5de0eaf1c8129 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:22:08 -0700 Subject: [PATCH 24/60] Find character at index --- src/StringPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index 42184f7..a8b3d85 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -13,6 +13,7 @@ public static void main(String[] args) { System.out.println(newWord); // Find the value of the character at index 3 + System.out.println(newWord.charAt(3)); // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) From b7e4637fe885d6a12925751fd44558eb570e0216 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 12:26:44 -0700 Subject: [PATCH 25/60] Added a space between the two strings --- src/StringPractice.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index a8b3d85..791ca5b 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -9,7 +9,7 @@ public static void main(String[] args) { // Concatenate (add) two strings together and reassign the result String word2 = "November"; - String newWord = word + word2; + String newWord = word + " " + word2; System.out.println(newWord); // Find the value of the character at index 3 @@ -17,6 +17,7 @@ public static void main(String[] args) { // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) + // Iterate over the characters of the string, printing each one on a separate line // Create an ArrayList of Strings and assign it to a variable From ce8bceae2cddfdb430c3bd24e4987f9ce197070a Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:22:43 -0700 Subject: [PATCH 26/60] Check String for substring --- src/StringPractice.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index 791ca5b..4170e61 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -16,7 +16,11 @@ public static void main(String[] args) { System.out.println(newWord.charAt(3)); // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) - + if (newWord.contains("Nov")){ + System.out.println("True"); + } else { + System.out.println("False"); + } // Iterate over the characters of the string, printing each one on a separate line From 0c28e0d05670b627ae72c6397c7c33c735c65425 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:29:28 -0700 Subject: [PATCH 27/60] Iterate through characters of the string, updated toRefresh --- src/StringPractice.java | 4 ++++ toRefresh.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index 4170e61..07aae4a 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -23,6 +23,10 @@ public static void main(String[] args) { } // Iterate over the characters of the string, printing each one on a separate line + for (int i = 0; i < newWord.length(); i++){ + char c = newWord.charAt(i); + System.out.println(c); + } // Create an ArrayList of Strings and assign it to a variable diff --git a/toRefresh.md b/toRefresh.md index 7f3b895..7fd2ee7 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -9,4 +9,5 @@ As you work through this exercise, write down anything that you needed to look u - .size() to get number of elements in list - Collections.sort() - Arrays vs Lists -- traditional for-loop for arrays \ No newline at end of file +- traditional for-loop for arrays +- charAt() to return the character at index \ No newline at end of file From 4650784985d6b2324e32f3aa0739f5c813e88723 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:33:51 -0700 Subject: [PATCH 28/60] Created an ArrayList of Strings --- src/StringPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index 07aae4a..bc885b2 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -1,3 +1,5 @@ +import java.util.ArrayList; + public class StringPractice { public static void main(String[] args) { // Create a string with at least 5 characters and assign it to a variable @@ -29,6 +31,7 @@ public static void main(String[] args) { } // Create an ArrayList of Strings and assign it to a variable + ArrayList list = new ArrayList<>(); // Add multiple strings to the List (OK to do one-by-one) From f7fa0f17bc8c814483bf4f5c64b8d443c9c3fae3 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:36:23 -0700 Subject: [PATCH 29/60] Add multiple strings to arraylist --- src/StringPractice.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index bc885b2..6acbe58 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -34,6 +34,11 @@ public static void main(String[] args) { ArrayList list = new ArrayList<>(); // Add multiple strings to the List (OK to do one-by-one) + list.add("Blue"); + list.add("White"); + list.add("Green"); + list.add("Red"); + System.out.println(list); // Join all of the strings in the list together into a single string separated by commas // Use a built-in method to achieve this instead of using a loop From 0ce987b97932142174318c928f1d785f9c2cf8ef Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:45:44 -0700 Subject: [PATCH 30/60] Used built in method to join strings together, updated toRefresh --- src/StringPractice.java | 2 ++ toRefresh.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index 6acbe58..ace353a 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -42,6 +42,8 @@ public static void main(String[] args) { // Join all of the strings in the list together into a single string separated by commas // Use a built-in method to achieve this instead of using a loop + String joinedString = String.join(", ", list); + System.out.println(joinedString); // Check whether two strings are equal diff --git a/toRefresh.md b/toRefresh.md index 7fd2ee7..13dbc3c 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -10,4 +10,5 @@ As you work through this exercise, write down anything that you needed to look u - Collections.sort() - Arrays vs Lists - traditional for-loop for arrays -- charAt() to return the character at index \ No newline at end of file +- charAt() to return the character at index +- .join() to join strings seperated by commas \ No newline at end of file From ba695b48bc78c5801555b07250eb795b7e0d58eb Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:54:13 -0700 Subject: [PATCH 31/60] Check if strings are equal --- src/StringPractice.java | 5 ++++- toRefresh.md | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index ace353a..4378ecf 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -23,7 +23,7 @@ public static void main(String[] args) { } else { System.out.println("False"); } - + // Iterate over the characters of the string, printing each one on a separate line for (int i = 0; i < newWord.length(); i++){ char c = newWord.charAt(i); @@ -46,6 +46,9 @@ public static void main(String[] args) { System.out.println(joinedString); // Check whether two strings are equal + String s = list.get(1); + String s2 = list.get(2); + System.out.println(s.equals(s2)); /* * Reminder! diff --git a/toRefresh.md b/toRefresh.md index 13dbc3c..0a06ed0 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -11,4 +11,5 @@ As you work through this exercise, write down anything that you needed to look u - Arrays vs Lists - traditional for-loop for arrays - charAt() to return the character at index -- .join() to join strings seperated by commas \ No newline at end of file +- .join() to join strings seperated by commas +- .equals() syntax \ No newline at end of file From 58ebbf0bf03dbf9c14757dc9997e79ae559c3443 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:06:57 -0700 Subject: [PATCH 32/60] Edit code on line 27, if string contains substring --- src/StringPractice.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/StringPractice.java b/src/StringPractice.java index 4378ecf..c5d18c9 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -18,12 +18,14 @@ public static void main(String[] args) { System.out.println(newWord.charAt(3)); // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) - if (newWord.contains("Nov")){ - System.out.println("True"); - } else { - System.out.println("False"); - } - + // if (newWord.contains("Nov")){ + // System.out.println("True"); + // } else { + // System.out.println("False"); + // } + + System.out.println(newWord.contains("Nov")); + // Iterate over the characters of the string, printing each one on a separate line for (int i = 0; i < newWord.length(); i++){ char c = newWord.charAt(i); From 1caadcf8a4ac877852ce1c7d772346ae87cf3f05 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:10:13 -0700 Subject: [PATCH 33/60] Created HashSet --- src/SetPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SetPractice.java b/src/SetPractice.java index d2fc1c9..94f54a3 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -1,6 +1,9 @@ +import java.util.*; + public class SetPractice { public static void main(String[] args) { // Create a HashSet of Strings and assign it to a variable of type Set + Set set = new HashSet<>(); // Add 3 elements to the set // (It's OK to do it one-by-one) From 3215d8251daa8d8014deeae45d2270b509fbf261 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:13:36 -0700 Subject: [PATCH 34/60] add 3 elements to set --- src/SetPractice.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/SetPractice.java b/src/SetPractice.java index 94f54a3..b6a11a9 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -7,6 +7,10 @@ public static void main(String[] args) { // Add 3 elements to the set // (It's OK to do it one-by-one) + set.add("Pen"); + set.add("Pencil"); + set.add("Eraser"); + System.out.println(set); // Check whether the Set contains a given String From c9bb46cb81074cd23ced546245281e4d3c719e01 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:14:52 -0700 Subject: [PATCH 35/60] check if set contains certain string --- src/SetPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SetPractice.java b/src/SetPractice.java index b6a11a9..93c6c1c 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -13,6 +13,7 @@ public static void main(String[] args) { System.out.println(set); // Check whether the Set contains a given String + System.out.println(set.contains("Pen")); // Remove an element from the Set From 836a624ecc6411286131e0b500fe7b816e89ff31 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:18:02 -0700 Subject: [PATCH 36/60] Removed element from set --- src/SetPractice.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/SetPractice.java b/src/SetPractice.java index 93c6c1c..16b6b16 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -13,9 +13,11 @@ public static void main(String[] args) { System.out.println(set); // Check whether the Set contains a given String - System.out.println(set.contains("Pen")); + System.out.println(set.contains("Pen")); // Remove an element from the Set + System.out.println(set.remove("Eraser")); + System.out.println(set); // Get the size of the Set From 2376040d0cc2cb0237c397bf29c65153376ced42 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:19:07 -0700 Subject: [PATCH 37/60] Get size of set --- src/SetPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/SetPractice.java b/src/SetPractice.java index 16b6b16..a30b980 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -20,6 +20,7 @@ public static void main(String[] args) { System.out.println(set); // Get the size of the Set + System.out.println(set.size()); // Iterate over the elements of the Set, printing each one on a separate line From a3b8d6efcdfdd7132fc3833c0d6d46c28f88b4b6 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:21:59 -0700 Subject: [PATCH 38/60] Iterate the set, updated toRefresh --- src/SetPractice.java | 3 +++ toRefresh.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SetPractice.java b/src/SetPractice.java index a30b980..c9c3270 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -23,6 +23,9 @@ public static void main(String[] args) { System.out.println(set.size()); // Iterate over the elements of the Set, printing each one on a separate line + for (String str : set) { + System.out.println(str); + } /* * Warning! diff --git a/toRefresh.md b/toRefresh.md index 0a06ed0..ab0023c 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -12,4 +12,5 @@ As you work through this exercise, write down anything that you needed to look u - traditional for-loop for arrays - charAt() to return the character at index - .join() to join strings seperated by commas -- .equals() syntax \ No newline at end of file +- .equals() syntax +- iterate a HashSet \ No newline at end of file From a61b1edb4cf2d5a001942f87de0bbbd23c8a6a9f Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:26:20 -0700 Subject: [PATCH 39/60] Created HashMap with String, Integer --- src/MapPractice.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index 7ebfeac..a83dca9 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -1,9 +1,10 @@ - +import java.util.*; public class MapPractice { public static void main(String[] args) { // Create a HashMap with String keys and Integer values and // assign it to a variable of type Map + Map dict = new HashMap<>(); // Put 3 different key/value pairs in the Map // (it's OK to do this one-by-one) From 3ec09255d5f2baec6a15abc9c94a865dadecf9b7 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:33:16 -0700 Subject: [PATCH 40/60] Added key/value pairs in Map, updated toRefresh --- src/MapPractice.java | 4 ++++ toRefresh.md | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index a83dca9..ad89e37 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -8,6 +8,10 @@ public static void main(String[] args) { // Put 3 different key/value pairs in the Map // (it's OK to do this one-by-one) + dict.put("Pooh", 1); + dict.put("Tigger", 3); + dict.put("Eeyore", 6); + System.out.println(dict); // Get the value associated with a given key in the Map diff --git a/toRefresh.md b/toRefresh.md index ab0023c..3affe30 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -13,4 +13,5 @@ As you work through this exercise, write down anything that you needed to look u - charAt() to return the character at index - .join() to join strings seperated by commas - .equals() syntax -- iterate a HashSet \ No newline at end of file +- iterate a HashSet +- .put() for Maps \ No newline at end of file From 1be48c5e43942e005176ceb3e993ec3ae97260c8 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:39:48 -0700 Subject: [PATCH 41/60] Get value to a give key, updated toRefresh --- src/MapPractice.java | 1 + toRefresh.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index ad89e37..72f5c10 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -14,6 +14,7 @@ public static void main(String[] args) { System.out.println(dict); // Get the value associated with a given key in the Map + System.out.println(dict.get("Eeyore")); // Find the size (number of key/value pairs) of the Map diff --git a/toRefresh.md b/toRefresh.md index 3affe30..2a00bc6 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -14,4 +14,5 @@ As you work through this exercise, write down anything that you needed to look u - .join() to join strings seperated by commas - .equals() syntax - iterate a HashSet -- .put() for Maps \ No newline at end of file +- .put() for Maps +- .get() access an item in HashMap \ No newline at end of file From 76e8a2435c349d3a51dd8fa04a17d8067060f810 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:41:48 -0700 Subject: [PATCH 42/60] Find size of map --- src/MapPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MapPractice.java b/src/MapPractice.java index 72f5c10..e52f361 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -17,6 +17,7 @@ public static void main(String[] args) { System.out.println(dict.get("Eeyore")); // Find the size (number of key/value pairs) of the Map + System.out.println(dict.size()); // Replace the value associated with a given key (the size of the Map shoukld not change) From 8d547ec1e89a5836dea38bf91a43a8069f514a67 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:48:14 -0700 Subject: [PATCH 43/60] Replaced value with given key, updated toRefresh --- src/MapPractice.java | 2 ++ toRefresh.md | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index e52f361..bde1daa 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -20,6 +20,8 @@ public static void main(String[] args) { System.out.println(dict.size()); // Replace the value associated with a given key (the size of the Map shoukld not change) + dict.replace("Pooh", 9); + System.out.println(dict); // Check whether the Map contains a given key diff --git a/toRefresh.md b/toRefresh.md index 2a00bc6..28e6825 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -15,4 +15,5 @@ As you work through this exercise, write down anything that you needed to look u - .equals() syntax - iterate a HashSet - .put() for Maps -- .get() access an item in HashMap \ No newline at end of file +- .get() access an item in HashMap +- HashMap ordering \ No newline at end of file From 15a6bd911f43afdcd4c2595057c75fa208bb2ad8 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:49:55 -0700 Subject: [PATCH 44/60] Check map if contains given key --- src/MapPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MapPractice.java b/src/MapPractice.java index bde1daa..15486ed 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -24,6 +24,7 @@ public static void main(String[] args) { System.out.println(dict); // Check whether the Map contains a given key + System.out.println(dict.containsKey("Tigger")); // Check whether the Map contains a given value From 15b8f6f1738a0c948a989f29950fc127d7d8842d Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:51:10 -0700 Subject: [PATCH 45/60] Check map if contains given value --- src/MapPractice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/MapPractice.java b/src/MapPractice.java index 15486ed..878a9a9 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -27,6 +27,7 @@ public static void main(String[] args) { System.out.println(dict.containsKey("Tigger")); // Check whether the Map contains a given value + System.out.println(dict.containsValue(9)); // Iterate over the keys of the Map, printing each key From 45f4481d807153fe79389ade5fd4106ad2fba88e Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:54:22 -0700 Subject: [PATCH 46/60] Iterate keys of Map, updated toRefresh --- src/MapPractice.java | 3 +++ toRefresh.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index 878a9a9..9ab1d4a 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -30,6 +30,9 @@ public static void main(String[] args) { System.out.println(dict.containsValue(9)); // Iterate over the keys of the Map, printing each key + for (String str : dict.keySet()){ + System.out.println(str); + } // Iterate over the values of the map, printing each value diff --git a/toRefresh.md b/toRefresh.md index 28e6825..e8ca5f2 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -16,4 +16,5 @@ As you work through this exercise, write down anything that you needed to look u - iterate a HashSet - .put() for Maps - .get() access an item in HashMap -- HashMap ordering \ No newline at end of file +- HashMap ordering +- iterate a HashMap \ No newline at end of file From 1f89273f1b901addcbae89a9e20e8184ad2e2735 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:55:55 -0700 Subject: [PATCH 47/60] Iterate values in map --- src/MapPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MapPractice.java b/src/MapPractice.java index 9ab1d4a..f1d6e72 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -35,6 +35,9 @@ public static void main(String[] args) { } // Iterate over the values of the map, printing each value + for (int v : dict.values()){ + System.out.println(v); + } // Iterate over the entries in the map, printing each key and value From 15dec6cfb1b0d920a22c3703885e1c1ec71468c8 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:00:54 -0700 Subject: [PATCH 48/60] Iterate over key/value pairs, updated toRefresh --- src/MapPractice.java | 3 +++ toRefresh.md | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index f1d6e72..76dcafe 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -40,6 +40,9 @@ public static void main(String[] args) { } // Iterate over the entries in the map, printing each key and value + for (String s : dict.keySet()){ + System.out.println("Key: " + s + ", Value: " + dict.get(s)); + } /* * Usage tip! diff --git a/toRefresh.md b/toRefresh.md index e8ca5f2..603d10b 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -17,4 +17,5 @@ As you work through this exercise, write down anything that you needed to look u - .put() for Maps - .get() access an item in HashMap - HashMap ordering -- iterate a HashMap \ No newline at end of file +- iterate a HashMap +- print both keys and values in Hashmap \ No newline at end of file From 7783699a79408e276ba650abfd43ae3224b296c5 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:11:26 -0700 Subject: [PATCH 49/60] Declared instance variables --- src/Person.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Person.java b/src/Person.java index 8ab3f95..17dda2c 100644 --- a/src/Person.java +++ b/src/Person.java @@ -6,6 +6,8 @@ public class Person { // Declare a public String instance variable for the name of the person // Declare a private int instance variable for the age of the person + public String name; + private int age; // Create a constructor that takes the name and age of the person From c1f3dd49c0985f3bf0a55fddfd1260afbdfd53b8 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:20:22 -0700 Subject: [PATCH 50/60] Created constructor, updated toRefresh --- src/Person.java | 8 +++++--- toRefresh.md | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Person.java b/src/Person.java index 17dda2c..c9b4077 100644 --- a/src/Person.java +++ b/src/Person.java @@ -9,13 +9,15 @@ public class Person { public String name; private int age; - // Create a constructor that takes the name and age of the person // and assigns it to the instance variables - + public Person(String name, int age) { + this.name = name; + this.age = age; + } // Create a toString method that gives the name and age of the person - + // Implement the below public instance method "birthYear" // There should NOT be any print statement in this method. diff --git a/toRefresh.md b/toRefresh.md index 603d10b..ea7e6af 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -18,4 +18,5 @@ As you work through this exercise, write down anything that you needed to look u - .get() access an item in HashMap - HashMap ordering - iterate a HashMap -- print both keys and values in Hashmap \ No newline at end of file +- print both keys and values in Hashmap +- creating a constructor \ No newline at end of file From c973a11ab3dab9447cedae4803a1b74d22841233 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:23:00 -0700 Subject: [PATCH 51/60] Created toString, updated toRefresh --- src/Person.java | 4 +++- toRefresh.md | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Person.java b/src/Person.java index c9b4077..536bd5d 100644 --- a/src/Person.java +++ b/src/Person.java @@ -17,7 +17,9 @@ public Person(String name, int age) { } // Create a toString method that gives the name and age of the person - + public String toString() { + return "Name: " + name + " Age: " + age; + } // Implement the below public instance method "birthYear" // There should NOT be any print statement in this method. diff --git a/toRefresh.md b/toRefresh.md index ea7e6af..b3ac520 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -19,4 +19,5 @@ As you work through this exercise, write down anything that you needed to look u - HashMap ordering - iterate a HashMap - print both keys and values in Hashmap -- creating a constructor \ No newline at end of file +- creating a constructor +- creating toString() \ No newline at end of file From c482443e2900b4a03cf87e8fe4543c5c899f5b38 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:31:45 -0700 Subject: [PATCH 52/60] Created birthYear method --- src/Person.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Person.java b/src/Person.java index 536bd5d..904dcdf 100644 --- a/src/Person.java +++ b/src/Person.java @@ -34,6 +34,10 @@ public String toString() { * @return The year the person was born */ // (create the instance method here) + public int birthYear(int currentYear) { + int birthYear = currentYear - age; + return birthYear; + } public static void main(String[] args) { From c12ae7a580d886698e464580f596b4ce7dc3b610 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:37:49 -0700 Subject: [PATCH 53/60] Created an instance of Person --- src/Person.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Person.java b/src/Person.java index 904dcdf..8cc666d 100644 --- a/src/Person.java +++ b/src/Person.java @@ -42,6 +42,7 @@ public int birthYear(int currentYear) { public static void main(String[] args) { // Create an instance of Person + Person p1 = new Person("Harry Potter", 27); // Create another instance of Person with a different name and age and // assign it to a different variable From 686ff427eaca64e28c60285b1d8120ac8ed36240 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:40:01 -0700 Subject: [PATCH 54/60] Created second intance of Person --- src/Person.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Person.java b/src/Person.java index 8cc666d..2fcc4c5 100644 --- a/src/Person.java +++ b/src/Person.java @@ -46,6 +46,7 @@ public static void main(String[] args) { // Create another instance of Person with a different name and age and // assign it to a different variable + Person p2 = new Person("Ron Weasley", 28); // Print the first person From 69432e75a3619412bfd551b6525855018017b265 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:40:51 -0700 Subject: [PATCH 55/60] Print first person --- src/Person.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Person.java b/src/Person.java index 2fcc4c5..c66670d 100644 --- a/src/Person.java +++ b/src/Person.java @@ -49,6 +49,7 @@ public static void main(String[] args) { Person p2 = new Person("Ron Weasley", 28); // Print the first person + System.out.println(p1); // Print the second person From c976449451b08255050ada44732cd43dd802b736 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:41:36 -0700 Subject: [PATCH 56/60] Print second person --- src/Person.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Person.java b/src/Person.java index c66670d..a614053 100644 --- a/src/Person.java +++ b/src/Person.java @@ -52,6 +52,7 @@ public static void main(String[] args) { System.out.println(p1); // Print the second person + System.out.println(p2); // Get the name of the first person and store it in a local variable From e48dc705a3e4f6a264771a390b84ba28bfe0e43d Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 16:44:54 -0700 Subject: [PATCH 57/60] Store first person's name in variable --- src/Person.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Person.java b/src/Person.java index a614053..529f934 100644 --- a/src/Person.java +++ b/src/Person.java @@ -55,6 +55,7 @@ public static void main(String[] args) { System.out.println(p2); // Get the name of the first person and store it in a local variable + String name1 = p1.name; // Using the birthYear method, get the birth year of the first person // and store it in a local variable. Input the actual current year (e.g. 2025) From 8272fcd7526e18459c0e29d6d03623540ba8c5ee Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 17:04:22 -0700 Subject: [PATCH 58/60] Find the persons birth year using method --- src/Person.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Person.java b/src/Person.java index 529f934..69898cd 100644 --- a/src/Person.java +++ b/src/Person.java @@ -56,10 +56,13 @@ public static void main(String[] args) { // Get the name of the first person and store it in a local variable String name1 = p1.name; + //System.out.println(name1); // Using the birthYear method, get the birth year of the first person // and store it in a local variable. Input the actual current year (e.g. 2025) // as the argument. + int age1 = p1.age; + int birthYear1 = p1.birthYear(2025); // In a separate statement, print the local variable holding the birth year. From 05b34b86bef5f7404151e5c5b217cd1e21516519 Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 17:08:19 -0700 Subject: [PATCH 59/60] Print first persons birth year, updated toRefresh --- src/Person.java | 1 + toRefresh.md | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Person.java b/src/Person.java index 69898cd..8846a16 100644 --- a/src/Person.java +++ b/src/Person.java @@ -65,6 +65,7 @@ public static void main(String[] args) { int birthYear1 = p1.birthYear(2025); // In a separate statement, print the local variable holding the birth year. + System.out.println(birthYear1); /** * Terminology! diff --git a/toRefresh.md b/toRefresh.md index b3ac520..0761090 100644 --- a/toRefresh.md +++ b/toRefresh.md @@ -20,4 +20,5 @@ As you work through this exercise, write down anything that you needed to look u - iterate a HashMap - print both keys and values in Hashmap - creating a constructor -- creating toString() \ No newline at end of file +- creating toString() +- review Java OOP \ No newline at end of file From e606dbc8a8a1b2e3ef8f4c83688b7eb51d1cf8aa Mon Sep 17 00:00:00 2001 From: Lilian <210286008+liliann19@users.noreply.github.com> Date: Wed, 1 Oct 2025 17:11:57 -0700 Subject: [PATCH 60/60] Reviewed code and edited some --- src/Person.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Person.java b/src/Person.java index 8846a16..30045da 100644 --- a/src/Person.java +++ b/src/Person.java @@ -56,12 +56,12 @@ public static void main(String[] args) { // Get the name of the first person and store it in a local variable String name1 = p1.name; - //System.out.println(name1); + System.out.println(name1); // Using the birthYear method, get the birth year of the first person // and store it in a local variable. Input the actual current year (e.g. 2025) // as the argument. - int age1 = p1.age; + //int age1 = p1.age; - don't need this int birthYear1 = p1.birthYear(2025); // In a separate statement, print the local variable holding the birth year.