Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d066397
Importing Arrays
Jaronie Mar 21, 2026
36ad3d5
Added 4 elements into the array with different String variables
Jaronie Mar 21, 2026
26785c9
Variable storing index 2 value
Jaronie Mar 21, 2026
61e3415
Length of array stored in int variable
Jaronie Mar 21, 2026
4a3a230
For loop printing each array item
Jaronie Mar 21, 2026
1da1ee2
For each loop printing out each array item
Jaronie Mar 21, 2026
ca667e0
Importing Java List
Jaronie Mar 21, 2026
c2e94ba
Empty ArrayList created, also import changed to ArrayList
Jaronie Mar 21, 2026
6238682
3 elements added to list
Jaronie Mar 21, 2026
ff618b9
Printing index 1 of ArrayList
Jaronie Mar 21, 2026
a4996de
Using set() to replace an index value
Jaronie Mar 21, 2026
6373342
using add() to a value to index 0, extending the arraylist length
Jaronie Mar 21, 2026
ed47094
Checking if a certain string exists within the list
Jaronie Mar 21, 2026
d35d850
Iterating using traditional loop, printing values and indexes on sepa…
Jaronie Mar 21, 2026
b16bbfd
importing collections
Jaronie Mar 21, 2026
1140921
Sorting the list
Jaronie Mar 21, 2026
f58513c
Using a for-each loop to iterate the list
Jaronie Mar 21, 2026
66b57ae
HashMap imported
Jaronie Mar 21, 2026
224868d
Created HashMap
Jaronie Mar 21, 2026
1bb096b
Type variable changed to Map
Jaronie Mar 21, 2026
a9cb21a
Import Map util
Jaronie Mar 21, 2026
033b763
Added 3 key pairs in the map
Jaronie Mar 21, 2026
1d9343f
Stored key value into a variable
Jaronie Mar 21, 2026
0e9d90d
map size stored into a variable
Jaronie Mar 21, 2026
e6c3c50
Replaced second key value
Jaronie Mar 21, 2026
e57f1a9
Checking if the map contains a given key
Jaronie Mar 21, 2026
ad0b875
Checking if map contains a given value
Jaronie Mar 21, 2026
98666e0
Using keySet() to iterate through keys with a for each loop.
Jaronie Mar 21, 2026
49522bb
Using values() to grab values of map, and storing them in type Intege…
Jaronie Mar 21, 2026
95be99a
Iterating each entry using Map.Entry type variable for the map, and p…
Jaronie Mar 21, 2026
84c6098
Negative float variable created
Jaronie Mar 21, 2026
d0f7eba
Last change: adding print lines under booleans checking for key/value.
Jaronie Mar 21, 2026
754557e
Created a remainder variable with modulus
Jaronie Mar 21, 2026
7ec4530
if/else statement checking for an even number.
Jaronie Mar 21, 2026
ac15cc7
Using integer division to divide a number.
Jaronie Mar 21, 2026
ab5a884
Printing the result of integer division
Jaronie Mar 21, 2026
f80a42f
Public and private instance variables made in Person
Jaronie Mar 21, 2026
2ba46ba
Created a person constructer with String name, and int age parameters.
Jaronie Mar 21, 2026
332a7ab
toString() method created
Jaronie Mar 21, 2026
5bd897e
Instance method birthYear created
Jaronie Mar 21, 2026
3fa407f
Instance of person object created
Jaronie Mar 21, 2026
37d44fa
New instance of Person object
Jaronie Mar 21, 2026
381f767
Printing person1 object
Jaronie Mar 21, 2026
5a92f41
Printing person2 object
Jaronie Mar 21, 2026
13feabb
Storing person1 name into a variable
Jaronie Mar 21, 2026
6753be1
Storing person1 birthYear into a variable
Jaronie Mar 21, 2026
8c21edf
Printing person1 birthYear
Jaronie Mar 21, 2026
cbe000e
Import java util HashSet
Jaronie Mar 21, 2026
6be387e
HashSet variable made
Jaronie Mar 21, 2026
4e6b317
MySert -> MySet. Also, added 3 elements to set.
Jaronie Mar 21, 2026
1d125c2
Boolean checking if a String value exists in set.
Jaronie Mar 21, 2026
6f28f11
removing value from set
Jaronie Mar 21, 2026
7f99e89
Iterating over each element, printed on a separate line.
Jaronie Mar 21, 2026
780ba2e
String variable made
Jaronie Mar 21, 2026
2a05c76
New string made from concatenation
Jaronie Mar 21, 2026
3686d27
char variable finding what character is at index 3
Jaronie Mar 21, 2026
e6e018b
Checking if string contains a substring
Jaronie Mar 21, 2026
f5a419d
Iterating through string to print each character
Jaronie Mar 21, 2026
5913ef7
Importing ArrayList
Jaronie Mar 21, 2026
68d84c0
New ArrayList variable
Jaronie Mar 21, 2026
08ed005
Multiple string elements added to list
Jaronie Mar 21, 2026
e84eebd
Using join() to join entire arrayList into one string separated by co…
Jaronie Mar 21, 2026
c328d96
Using .equals() and a boolean to check if two strings are equal
Jaronie Mar 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/ArrayPractice.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import java.util.Arrays;
public class ArrayPractice {

public static void main(String[] args) {
// Create an array of Strings of size 4
String[] arr = 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
arr[0] = "This";
arr[1] = "is";
arr[2] = "an";
arr[3] = "array";

// Get the value of the array at index 2
String valueAtIndex2 = arr[2]; // Receiving the value at index 2

// Get the length of the array
int lengthOfArray = arr.length; // Length of array

// Iterate over the array using a traditional for loop and print out each item
for(int i = 0; i < arr.length; i++){
System.out.println(arr[i]);
}

// Iterate over the array using a for-each loop and print out each item

for(String item : arr){
System.out.println(item);
}
/*
* Reminder!
*
Expand Down
19 changes: 19 additions & 0 deletions src/ListPractice.java
Original file line number Diff line number Diff line change
@@ -1,27 +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<String> myList = new ArrayList<>();

// Add 3 elements to the list (OK to do one-by-one)
myList.add("First");
myList.add("Second");
myList.add("Third");

// Print the element at index 1
System.out.println(myList.get(1)); // Getting the element at index 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)
myList.set(1, "replaced value"); // Replacing the element at index 1 with .set()

// Insert a new element at index 0 (the length of the list will change)
myList.add(0, "new value here"); // Inserting a new element

// Check whether the list contains a certain string
boolean containsString = myList.contains("First"); // Checking if the list contains "First"
System.out.println("List contains a string: " + containsString);

// Iterate over the list using a traditional for-loop.
// Print each index and value on a separate line
for(int i = 0; i < myList.size(); i++){
System.out.println("Index: " + i + "\n" + "Value: " + myList.get(i));
}

// Sort the list using the Collections library
Collections.sort(myList); // Sorting the list

// Iterate over the list using a for-each loop
// Print each value on a second line
for(String item : myList){
System.out.println(item);
}

/*
* Usage tip!
Expand Down
24 changes: 23 additions & 1 deletion src/MapPractice.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@

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<String, Integer> myMap = new HashMap<>();


// Put 3 different key/value pairs in the Map
// (it's OK to do this one-by-one)
myMap.put("First", 1);
myMap.put("Second", 2);
myMap.put("Third", 3);

// Get the value associated with a given key in the Map
int valueForKey = myMap.get("Second"); // Getting the value for the key "Second"

// Find the size (number of key/value pairs) of the Map
int mapSize = myMap.size(); // Size of the map

// Replace the value associated with a given key (the size of the Map shoukld not change)
myMap.put("Second", 22); // Replacing the value for the key "Second"

// Check whether the Map contains a given key
boolean containsKey = myMap.containsKey("First");
System.out.println("Map contains key: " + containsKey);

// Check whether the Map contains a given value
boolean containsValue = myMap.containsValue(3);
System.out.println("Map contains value: " + containsValue);

// Iterate over the keys of the Map, printing each key

for(String key : myMap.keySet()){ // using keySet() to grab all keys
System.out.println(key);
}
// Iterate over the values of the map, printing each value
for(Integer value : myMap.values()) { // using values() to grab all values, with Integer type
System.out.println(value);
}

// Iterate over the entries in the map, printing each key and value
for(Map.Entry<String, Integer> entry : myMap.entrySet()) { // using entrySet() to grab all entries with Entry type.
System.out.println("Key: " + entry.getKey() + "\n" + "Value: " + entry.getValue());
}

/*
* Usage tip!
Expand Down
11 changes: 11 additions & 0 deletions src/NumberPractice.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
public class NumberPractice {
public static void main(String args[]) {
// Create a float with a negative value and assign it to a variable
float negativeFloat = -3.14f; // Creating a float with a negative value

// Create an int with a positive value and assign it to a variable
int posInt = 42; // Creating an int with a positive value

// Use the modulo % operator to find the remainder when the int is divided by 3
int remainder = posInt % 3; // Remainder given 3 as the divisor
System.out.println(remainder); // printing 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)
// Use an if-else to print "Even" if the number is even and "Odd"
// if the number is odd.
if(posInt % 2 == 0){
System.out.println("Even");
} else {
System.out.println("Odd");
}

// Divide the number by another number using integer division
int divisionResult = posInt / 5; // Integer division
System.out.println(divisionResult); // printing result of integer division

/*
* Reminder!
Expand Down
20 changes: 20 additions & 0 deletions src/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
public String toString(){
return "Name: " + name + "\n" + "Age: " + age;
}


// Implement the below public instance method "birthYear"
Expand All @@ -28,25 +37,36 @@ public class Person {
* @return The year the person was born
*/
// (create the instance method here)
public int birthYear(int year){
int birthYear = year - age;
return birthYear;
}


public static void main(String[] args) {
// Create an instance of Person
Person person1 = new Person("Jaron", 19); // creating new instance of Person object

// Create another instance of Person with a different name and age and
// assign it to a different variable
Person person2 = new Person("Maxwell", 10); // creating another instance of Person object

// Print the first person
System.out.println(person1);

// Print the second person
System.out.println(person2);

// Get the name of the first person and store it in a local variable
String name1 = person1.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 birthYear = person1.birthYear(2025);

// In a separate statement, print the local variable holding the birth year.
System.out.println("Birth year of " + name1 + ": " + birthYear);

/**
* Terminology!
Expand Down
14 changes: 14 additions & 0 deletions src/SetPractice.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import java.util.HashSet;

public class SetPractice {
public static void main(String[] args) {
// Create a HashSet of Strings and assign it to a variable of type Set
HashSet<String> mySet = new HashSet<>();


// Add 3 elements to the set
// (It's OK to do it one-by-one)
mySet.add("First");
mySet.add("Second");
mySet.add("Third");

// Check whether the Set contains a given String
boolean containsString = mySet.contains("Second"); // checking if a given string exists in set
System.out.println("Set contains string: " + containsString);

// Remove an element from the Set
mySet.remove("Second");

// Get the size of the Set
int setSize = mySet.size(); // size of the set

// Iterate over the elements of the Set, printing each one on a separate line
for(String item : mySet){ // using for-each loop to iterate over the set
System.out.println(item);
}

/*
* Warning!
Expand Down
23 changes: 22 additions & 1 deletion src/StringPractice.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,46 @@
public class StringPractice {
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
String fiveLetterString = "Hello";

// Find the length of the string
fiveLetterString.length();


// Concatenate (add) two strings together and reassign the result
String newString = fiveLetterString + "World"; // Concatenating two strings together

// Find the value of the character at index 3
char charAtIndex3 = fiveLetterString.charAt(3); // Getting the character at index 3

// Check whether the string contains a given substring (i.e. does the string have "abc" in it?)
boolean checkSubstring = fiveLetterString.contains("llo");

// Iterate over the characters of the string, printing each one on a separate line
for(int i = 0; i < fiveLetterString.length(); i++){
System.out.println(fiveLetterString.charAt(i)); // using charAt to print each index
}

// Create an ArrayList of Strings and assign it to a variable
ArrayList<String> myArrayList = new ArrayList<>();

// Add multiple strings to the List (OK to do one-by-one)
myArrayList.add("First");
myArrayList.add("Second");
myArrayList.add("Third");

// 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(",", myArrayList); // Joining the strings in the list together with commas using .join();

// Check whether two strings are equal
String string1 = "Hello";
String string2 = "world";

boolean stringsEqual = string1.equals(string2); // Checking if two strings are equal with .equals()

/*
* Reminder!
Expand Down