From fde04e92f3fa9e46faebebb5e540da13279f8f40 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:26:39 -0700 Subject: [PATCH 01/13] Setup basic variables needed for file --- src/NumberPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index bbec2fe..6082770 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -1,10 +1,13 @@ public class NumberPractice { public static void main(String args[]) { // Create a float with a negative value and assign it to a variable + float negativeFloat = -1.0f; // Create an int with a positive value and assign it to a variable + int positiveInt = 14; // Use the modulo % operator to find the remainder when the int is divided by 3 + int remainder = (positiveInt % 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 0a12aeca1029107a9a362a151ab0db604a5aabab Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:36:17 -0700 Subject: [PATCH 02/13] Add check even/odd functionality to file --- src/NumberPractice.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index 6082770..1d8592c 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -4,7 +4,7 @@ public static void main(String args[]) { float negativeFloat = -1.0f; // Create an int with a positive value and assign it to a variable - int positiveInt = 14; + int positiveInt = 15; // Use the modulo % operator to find the remainder when the int is divided by 3 int remainder = (positiveInt % 3); @@ -13,7 +13,12 @@ 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 (positiveInt % 2 == 0) { + System.out.println("Number is Odd!"); + } else { + System.out.println("Number is Even!"); + } + // Divide the number by another number using integer division /* From 36c898a3cf5b6c1e9d9f0848fcf5f7ea7050daba Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:41:11 -0700 Subject: [PATCH 03/13] Fixed bug with if statment and added the final integer division --- src/NumberPractice.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index 1d8592c..5df7af2 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -13,13 +13,14 @@ 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 (positiveInt % 2 == 0) { - System.out.println("Number is Odd!"); + if ((positiveInt % 2) == 0) { + System.out.println("Even!"); } else { - System.out.println("Number is Even!"); + System.out.println("Odd!"); } // Divide the number by another number using integer division + int dividedNum = positiveInt / 5; /* * Reminder! From 001bc750e8776394c21288be348d980481eaf77b Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:44:13 -0700 Subject: [PATCH 04/13] Number Practice file final build, stable. --- src/NumberPractice.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/NumberPractice.java b/src/NumberPractice.java index 5df7af2..7b6fef2 100644 --- a/src/NumberPractice.java +++ b/src/NumberPractice.java @@ -2,12 +2,14 @@ public class NumberPractice { public static void main(String args[]) { // Create a float with a negative value and assign it to a variable float negativeFloat = -1.0f; + System.out.println("Negative Float Value: " + negativeFloat); // Create an int with a positive value and assign it to a variable int positiveInt = 15; // Use the modulo % operator to find the remainder when the int is divided by 3 int remainder = (positiveInt % 3); + System.out.println("Remainder: " + remainder); // 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) @@ -21,6 +23,7 @@ public static void main(String args[]) { // Divide the number by another number using integer division int dividedNum = positiveInt / 5; + System.out.println("Integer Division: " + dividedNum); /* * Reminder! From 706db7dd720a0f0554ffce83a5b5ddfcae9ae502 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 18:53:16 -0700 Subject: [PATCH 05/13] Array creation and population --- src/ListPractice.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/ListPractice.java b/src/ListPractice.java index f4de8e7..b8bebb4 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -1,20 +1,30 @@ +import java.util.ArrayList; + public class ListPractice { public static void main(String[] args) { // Create an empty ArrayList of Strings and assign it to a variable of type List + ArrayList myStrings = new ArrayList<>(); // Add 3 elements to the list (OK to do one-by-one) + myStrings.add("String #1"); + myStrings.add("String #2"); + myStrings.add("String #3"); // Print the element at index 1 + System.out.println(myStrings.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) + myStrings.set(1, "New String #2"); // Insert a new element at index 0 (the length of the list will change) + myStrings.addFirst("New First Element!"); // 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 0f5e602640b1e1ee9f65618c312fc3cfa280ed42 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 19:06:01 -0700 Subject: [PATCH 06/13] List practice file complete, stable. --- src/ListPractice.java | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/ListPractice.java b/src/ListPractice.java index b8bebb4..173d110 100644 --- a/src/ListPractice.java +++ b/src/ListPractice.java @@ -1,37 +1,46 @@ import java.util.ArrayList; +import java.util.Collections; public class ListPractice { - public static void main(String[] args) { // Create an empty ArrayList of Strings and assign it to a variable of type List ArrayList myStrings = new ArrayList<>(); // Add 3 elements to the list (OK to do one-by-one) - myStrings.add("String #1"); - myStrings.add("String #2"); - myStrings.add("String #3"); + myStrings.add("I love dogs!"); + myStrings.add("Hey there."); + myStrings.add("Avengers, assemble."); // Print the element at index 1 System.out.println(myStrings.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) - myStrings.set(1, "New String #2"); + myStrings.set(1, "Woah, I'm different!"); // Insert a new element at index 0 (the length of the list will change) - myStrings.addFirst("New First Element!"); + myStrings.addFirst("New guy here..."); // Check whether the list contains a certain string - + // EXPECTED: TRUE + System.out.println("Contains new guy?: " + myStrings.contains("New guy here...")); // Iterate over the list using a traditional for-loop. // Print each index and value on a separate line + for (int i = 0; i < myStrings.size(); i++) { + System.out.println("[" + myStrings.get(i) + "]" + " at " + "index " + i); + } // Sort the list using the Collections library + Collections.sort(myStrings); // Iterate over the list using a for-each loop // Print each value on a second line + System.out.println(); + for (String x : myStrings) { + System.out.println(x); + } /* * Usage tip! From eae91584a59f1b59961e3f7095f4d4e28b589080 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 19:47:32 -0700 Subject: [PATCH 07/13] Completed Array Practice file, Stable. --- src/ArrayPractice.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ArrayPractice.java b/src/ArrayPractice.java index bc58c83..1f39fd6 100644 --- a/src/ArrayPractice.java +++ b/src/ArrayPractice.java @@ -1,17 +1,30 @@ public class ArrayPractice { public static void main(String[] args) { // Create an array of Strings of size 4 + String[] strings = 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 + strings[0] = "Hello"; + strings[1] = "What's up!"; + strings[2] = "Greetings."; + strings[3] = "Howdy!"; // Get the value of the array at index 2 + System.out.println(strings[2]); // Get the length of the array + System.out.println(strings.length); // Iterate over the array using a traditional for loop and print out each item + for (int i = 0; i < strings.length; i++) { + System.out.println(strings[i]); + } // Iterate over the array using a for-each loop and print out each item + for (String x : strings) { + System.out.println(x); + } /* * Reminder! From aad02e44e4abd4ea98416ca985dc45a136283599 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 19:56:08 -0700 Subject: [PATCH 08/13] Finished first portion of tasks --- src/StringPractice.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index 8d87617..f3478d1 100644 --- a/src/StringPractice.java +++ b/src/StringPractice.java @@ -1,16 +1,24 @@ public class StringPractice { public static void main(String[] args) { // Create a string with at least 5 characters and assign it to a variable + String myString = "Ahmed"; // Find the length of the string + System.out.println("String Length: " + myString.length()); // Concatenate (add) two strings together and reassign the result + myString = (myString + "Heythere!"); // Find the value of the character at index 3 + System.out.println("Value at index three: " + myString.charAt(3)); // Check whether the string contains a given substring (i.e. does the string have "abc" in it?) + System.out.println("Contains Ahm?: " + myString.contains("Ahm")); // Iterate over the characters of the string, printing each one on a separate line + for (int i = 0; i < myString.length(); i++) { + System.out.println(myString.charAt(i)); + } // Create an ArrayList of Strings and assign it to a variable From 3ae5e06ccf8eb5a57fa8a2c1491975009094a8fc Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:05:38 -0700 Subject: [PATCH 09/13] Completed String Practice, stable. --- src/StringPractice.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/StringPractice.java b/src/StringPractice.java index f3478d1..72da9fb 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 @@ -21,13 +23,20 @@ public static void main(String[] args) { } // Create an ArrayList of Strings and assign it to a variable + ArrayList myArray = new ArrayList<>(); // Add multiple strings to the List (OK to do one-by-one) + myArray.add("Wuzzup"); + myArray.add("Hello yo!"); + myArray.add("I like cheese."); // 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 test = String.join(", ", myArray); + System.out.println(test); // Check whether two strings are equal + System.out.println("They equal?: " + myArray.get(0).equals(myArray.get(1))); /* * Reminder! From 40cc7e958d1c91b5d230706d11f82f5eb7df99cf Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:12:36 -0700 Subject: [PATCH 10/13] Completed Set Practice file, stable --- src/SetPractice.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SetPractice.java b/src/SetPractice.java index d2fc1c9..b21a7ad 100644 --- a/src/SetPractice.java +++ b/src/SetPractice.java @@ -1,17 +1,30 @@ +import java.util.HashSet; +import java.util.Set; + public class SetPractice { public static void main(String[] args) { // Create a HashSet of Strings and assign it to a variable of type Set + Set myStrings = new HashSet<>(); // Add 3 elements to the set // (It's OK to do it one-by-one) + myStrings.add("One"); + myStrings.add("Two"); + myStrings.add("Three"); // Check whether the Set contains a given String + System.out.println(myStrings.contains("Two")); // Remove an element from the Set + myStrings.remove("Three"); // Get the size of the Set + System.out.println(myStrings.size()); // Iterate over the elements of the Set, printing each one on a separate line + for (String x : myStrings) { + System.out.println(x); + } /* * Warning! From 3f9748355db303dfbf863e9807ae358aec7b8bc2 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:33:54 -0700 Subject: [PATCH 11/13] complete practice map --- src/MapPractice.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/MapPractice.java b/src/MapPractice.java index 7ebfeac..0252a4f 100644 --- a/src/MapPractice.java +++ b/src/MapPractice.java @@ -1,28 +1,47 @@ - +import java.util.HashMap; +import java.util.Map; 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 myMap = new HashMap<>(); // Put 3 different key/value pairs in the Map // (it's OK to do this one-by-one) + myMap.put("One", 1); + myMap.put("Two", 2); + myMap.put("Three", 3); // Get the value associated with a given key in the Map + System.out.println(myMap.get("One")); // Find the size (number of key/value pairs) of the Map + System.out.println(myMap.size()); // Replace the value associated with a given key (the size of the Map shoukld not change) + myMap.replace("One", 0); // Check whether the Map contains a given key + System.out.println("Contains Key One: " + myMap.containsKey("One")); // Check whether the Map contains a given value + System.out.println("Contains Value 1: " + myMap.containsValue(1)); // Iterate over the keys of the Map, printing each key + for (String key : myMap.keySet()) { + System.out.println(key); + } // Iterate over the values of the map, printing each value + for (int value : myMap.values()) { + System.out.println(value); + } // Iterate over the entries in the map, printing each key and value + for (Map.Entry entry : myMap.entrySet()) { + System.out.println("Key: " + entry.getKey() + ", Value: " + entry.getValue()); + } /* * Usage tip! From aa22956b4d8aad6e5622305dd9a8b9565e46b9f1 Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:42:27 -0700 Subject: [PATCH 12/13] Person class functionality added --- src/Person.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Person.java b/src/Person.java index 8ab3f95..5aac9b6 100644 --- a/src/Person.java +++ b/src/Person.java @@ -6,13 +6,22 @@ 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 // 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 + @Override + public String toString () { + return name + " " + age; + } // Implement the below public instance method "birthYear" @@ -28,10 +37,14 @@ public class Person { * @return The year the person was born */ // (create the instance method here) + public int birthYear (int currentYear) { + return currentYear - age; + } public static void main(String[] args) { // Create an instance of Person + // Create another instance of Person with a different name and age and // assign it to a different variable From 1fbe65e1ef209d7830e4cac3a5d1ba98e743df6c Mon Sep 17 00:00:00 2001 From: AI <182692506+AhmedIhsan123@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:46:13 -0700 Subject: [PATCH 13/13] Completed Person file, stable. --- src/Person.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Person.java b/src/Person.java index 5aac9b6..b812d03 100644 --- a/src/Person.java +++ b/src/Person.java @@ -44,22 +44,28 @@ public int birthYear (int currentYear) { public static void main(String[] args) { // Create an instance of Person - + Person me = new Person("Ahmed", 18); // Create another instance of Person with a different name and age and // assign it to a different variable + Person friend = new Person("Amelia", 20); // Print the first person + System.out.println(me.name); // Print the second person + System.out.println(friend.name); // Get the name of the first person and store it in a local variable + String myName = me.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) // as the argument. + int myYear = me.birthYear(2025); // In a separate statement, print the local variable holding the birth year. + System.out.println(myYear); /** * Terminology!