Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c447125
created an array name my array that hold 4 strings
Ebtisam0402 Oct 1, 2025
c0cd688
set the five value with their index
Ebtisam0402 Oct 1, 2025
a035beb
run code get highline
Ebtisam0402 Oct 1, 2025
a2ad92e
the length of an array 4
Ebtisam0402 Oct 1, 2025
52b391e
accessed each element using for loop
Ebtisam0402 Oct 1, 2025
6c3db9b
used for each loop to get each element
Ebtisam0402 Oct 1, 2025
e945579
first I imported java .util.list.Then I created an empty arratlist of…
Ebtisam0402 Oct 1, 2025
c162cd8
I used the set method and replace index 1 with out changing the ength…
Ebtisam0402 Oct 1, 2025
4bc80fb
Created a new element and used the add method and the length has been…
Ebtisam0402 Oct 1, 2025
0e4fbc7
I used list.contains to check a if it contains certain string (manar)…
Ebtisam0402 Oct 1, 2025
1758a20
for-loop created and the index and value in newline.
Ebtisam0402 Oct 1, 2025
83acb7c
the last two steps I sorted the elements using collections.sorrt. and…
Ebtisam0402 Oct 2, 2025
1d16803
created hashMap called people.
Ebtisam0402 Oct 2, 2025
322ec7c
used put method to add three people key and value
Ebtisam0402 Oct 2, 2025
6ef387c
for loop to get the value associated with the key in the map
Ebtisam0402 Oct 2, 2025
2f34ac4
used size()method
Ebtisam0402 Oct 2, 2025
4d0409d
using the replace and by specifing which string to be change using ke…
Ebtisam0402 Oct 2, 2025
374e7d8
cheched if each key and value have the element by using the method co…
Ebtisam0402 Oct 2, 2025
147343a
used map.keyset() method returns the key and map.values returns the v…
Ebtisam0402 Oct 2, 2025
8fe6544
loo over the keys and searching for the value
Ebtisam0402 Oct 2, 2025
52c24ea
float is a fraction number or decimal. integer is a whole number. mod…
Ebtisam0402 Oct 2, 2025
7acae54
get the even or odd by using modulo operation when divid 8 by 2 the r…
Ebtisam0402 Oct 2, 2025
0c55e75
divide two integers and the result will be rounded or the remaider is…
Ebtisam0402 Oct 2, 2025
e0f331a
from the person class declare as a public string (name) and private i…
Ebtisam0402 Oct 2, 2025
5015cf4
created a Hashset object called shools. Then I added each element usi…
Ebtisam0402 Oct 2, 2025
e2dd077
using the contains method , I checked if school name or string is their
Ebtisam0402 Oct 2, 2025
bd834a1
used the remove method and for the size, I used size method (shcool.s…
Ebtisam0402 Oct 2, 2025
565dbbf
used for loop to print it in each line.
Ebtisam0402 Oct 2, 2025
8eaaff0
variable name massage I created string with characters.
Ebtisam0402 Oct 2, 2025
0f8c8f9
found the length of the string which struggle coding
Ebtisam0402 Oct 2, 2025
58e9940
created two strings and then add them or used an addition sign.
Ebtisam0402 Oct 2, 2025
25b5702
this string has two p's so it gave me the the first p at index 2. I d…
Ebtisam0402 Oct 2, 2025
0f8c874
used contains method
Ebtisam0402 Oct 2, 2025
7f5b09a
I couldn't solve the iterate over the character
Ebtisam0402 Oct 2, 2025
00fee17
created array list of string with an empty list. then added two strings
Ebtisam0402 Oct 2, 2025
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
22 changes: 18 additions & 4 deletions src/ArrayPractice.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
public class ArrayPractice {
public static void main(String[] args) {
// Create an array of Strings of size 4

String[]myArray;
myArray = 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

myArray[0] = "Green River";
myArray[1] = "Seattle Central";
myArray[2] = "Highline";
myArray[3] = "South Seattle";

// Get the value of the array at index 2
System.out.println(myArray[2]);

// Get the length of the array
System.out.println(myArray.length);

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

for (int i =0; i<myArray.length; i++){
System.out.println("Element at index " + i + ": " +myArray[i]);
}
// Iterate over the array using a for-each loop and print out each item

for (String myArray1 : myArray ){
System.out.println(myArray1);
}

}
/*
* Reminder!
*
* Arrays start at index 0
*/
}
}

31 changes: 26 additions & 5 deletions src/ListPractice.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

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<String>list = new ArrayList<>();

// Add 3 elements to the list (OK to do one-by-one)

list.add("Ebtisam");
list.add("Manar");
list.add("Afnan");
list.set(1,"Semah");
list.add(0,"Abdulaziz");
// Print the element at index 1

System.out.println(list.get(1));
// Replace the element at index 1 with a new value
//I used the set method to replace the list with new value.
System.out.println(list);
// (Do not insert a new value. The length of the list should not change)

// Insert a new element at index 0 (the length of the list will change)

// I used add method to add the element.
// Check whether the list contains a certain string

System.out.println("Contains a certain string manar :" + list.contains("manar"));

// 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++){
System.out.println( ( "index:" +"["+ i+"]" )+list.get(i) );
}


// 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

for (String i: list){
System.out.println(i);
}
/*
* Usage tip!
*
Expand Down
34 changes: 27 additions & 7 deletions src/MapPractice.java
Original file line number Diff line number Diff line change
@@ -1,30 +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> people = new HashMap<>();

// Put 3 different key/value pairs in the Map
// (it's OK to do this one-by-one)

people.put("Manar", 10);
people.put("Afnan", 6);
people.put("Semah", 4);

// Get the value associated with a given key in the Map
for(String i:people.keySet() ){
System.out.println("key: " + i + " value: " + people.get(i));
}

// Find the size (number of key/value pairs) of the Map
System.out.println(people.size());

// Replace the value associated with a given key (the size of the Map shoukld not change)

String keyToReplace ="Afnan";
Integer newValue = 5;
people.replace(keyToReplace,newValue);
System.out.println(people);
// Check whether the Map contains a given key

System.out.println("Is the given key Semah present?" + people.containsKey("Semah"));
// Check whether the Map contains a given value
System.out.println("Is the given value 3 present?" + people.containsValue(3));

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

for(String name: people.keySet()){
System.out.println("key:" + name);
}
// Iterate over the values of the map, printing each value

for(Integer age: people.values()){
System.out.println("valu:" + age);
}
// Iterate over the entries in the map, printing each key and value

/*
for(String i: people.keySet()){
Integer age = people.get(i);
System.out.println("key: " + i + " valu: " + age);
}/*
* Usage tip!
*
* Maps are great when you want a specific key to value mapping.
Expand Down
22 changes: 18 additions & 4 deletions src/NumberPractice.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
public class NumberPractice {
public static void main(String args[]) {
// Create a float with a negative value and assign it to a variable

float myFloat = -6.1f;
System.out.println(myFloat);
// Create an int with a positive value and assign it to a variable

int myInt = 250;
System.out.println(myInt);
// Use the modulo % operator to find the remainder when the int is divided by 3

int a = 8;
int b = 3;
int x = a%b;
System.out.println(x);
// 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 (a % 2 == 0){
System.out.println(a + " Even");
}else{
System.out.println(a + " Odd");
}


// Divide the number by another number using integer division

int c = 18;
int d = 5;
int y =c/d ;
System.out.println(y);
/*
* Reminder!
*
Expand Down
15 changes: 9 additions & 6 deletions src/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

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


// Create a constructor that takes the name and age of the person
// and assigns it to the instance variables

public String name;
// Declare a private int instance variable for the age of the person
private int age;


// Create a constructor that takes the name and age of the person
// and assigns it to the instance variables
this.name = personname;
this.age= personage;
Comment on lines +13 to +16
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this file is incomplete. I strongly recommend going back and doing it! Feel free to come by office hours or tutoring for help.


// Create a toString method that gives the name and age of the person

Expand Down
16 changes: 14 additions & 2 deletions src/SetPractice.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
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> schools = new HashSet<>();
// Add 3 elements to the set
// (It's OK to do it one-by-one)
schools.add("Green River");
schools.add("Seattle Central");
schools.add("lake youngs");
System.out.println(schools);


// Check whether the Set contains a given String
System.out.println(schools.contains("Green River"));

// Remove an element from the Set
System.out.println(schools.remove("Seattle Central"));

// Get the size of the Set
System.out.println(schools.size());

// Iterate over the elements of the Set, printing each one on a separate line

for (String i : schools){
System.out.println(i);
}
/*
* Warning!
*
Expand Down
23 changes: 18 additions & 5 deletions src/StringPractice.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
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 message = "Struggle Coding";
System.out.println(message);
// Find the length of the string
System.out.println(message.length());

// Concatenate (add) two strings together and reassign the result

String message1= "Happy";
String message2= "Friday!";
String message3 =message1 + message2;
System.out.println(message3);
// Find the value of the character at index 3

System.out.println(message3.indexOf("p"));
// Check whether the string contains a given substring (i.e. does the string have "abc" in it?)

System.out.println(message3.contains("abc"));
// Iterate over the characters of the string, printing each one on a separate line

x = message + message3;
System.out.println(x);


// Create an ArrayList of Strings and assign it to a variable

ArrayList<String> colors = new ArrayList<>();
// Add multiple strings to the List (OK to do one-by-one)
colors.add ("Red");
colors.add ("Brown");

// 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
Expand Down