Looking back at team teach
I was part of group 9, we taught inheritance and my personal part of that lesson was hierarchies. I feel as if my group did an alright job presenting, but started to fall apart in the last two parts. The lesson was overall quite difficult to teach and understand as it requires understanding of both classes and what we are teaching, so if anything along the way gets messed up, it will be difficult to learn. While our presentation may not have been the best, I think our documents for the topics still were quite well-designed and easy to understand. Along the way, I have learned a lot about classes and inheritance, and I have figured out that my favorite lesson is classes. Classes are the basis of java teaching and are strictly necessary to the understanding of the language. This makes sense for me since I typically take interest in things I know will be useful to understand for my future.
Sprint 2 Review/Notes
In this notebook, I reflect on several key programming concepts in Java, including arrays, objects, 2D arrays, classes, ArrayLists, and inheritance. Each section includes a code example along with my explanations.
Unit 6 - Arrays
Arrays are data structures that can hold multiple values of the same type. They allow me to store lists of items in a single variable.
// Example of an array in Java
public class ArrayExample {
public static void main(String[] args) {
int[] numbers = {1, 2, 3, 4, 5};
// Accessing the first element in the array
int firstNumber = numbers[0];
System.out.println("The first number is: " + firstNumber);
}
}
In this example, I created an array called numbers
that holds five integers. I accessed the first element of the array using its index (0) and printed it.
Unit 2 - Using Objects
Objects are instances of classes that encapsulate data and functionality. They enable me to model real-world entities in my code.
// Example of using an object in Java
class Dog {
String name;
Dog(String name) {
this.name = name;
}
String bark() {
return name + " says woof!";
}
}
public class ObjectExample {
public static void main(String[] args) {
Dog myDog = new Dog("Rex");
System.out.println(myDog.bark());
}
}
In this example, I defined a class Dog
with a constructor that initializes its name
. I also defined a method bark
that returns a string. Then, I created an instance of Dog
and called its bark
method.
Unit 8 - 2D Arrays
Taught: 9/27
2D arrays are arrays of arrays, allowing me to represent tabular data. They can be useful for matrices or grids.
// Example of a 2D array in Java
public class TwoDArrayExample {
public static void main(String[] args) {
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
// Accessing an element in the 2D array
int element = matrix[1][2]; // Access the element at row 1, column 2
System.out.println("The accessed element is: " + element);
}
}
In this example, I created a 2D array called matrix
. I accessed an element at row 1, column 2 and printed it.
Unit 5 - Writing Classes
Taught: 10/1
Classes are blueprints for creating objects. They define properties and methods that the objects created from them will have.
// Example of a class in Java
class Car {
String make;
String model;
Car(String make, String model) {
this.make = make;
this.model = model;
}
String describe() {
return "This car is a " + make + " " + model;
}
}
public class ClassExample {
public static void main(String[] args) {
Car myCar = new Car("Toyota", "Corolla");
System.out.println(myCar.describe());
}
}
In this example, I defined a Car
class with properties for make
and model
. I created an instance of the class and called the describe
method to print its details.
Unit 7 - ArrayLists
Taught: 10/2
ArrayLists are dynamic arrays that can grow and shrink in size. They provide more flexibility compared to regular arrays.
// Example of an ArrayList in Java
import java.util.ArrayList;
public class ArrayListExample {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<>();
// Adding elements to the ArrayList
arrayList.add("apple");
arrayList.add("banana");
// Removing an element
arrayList.remove("apple");
// Displaying the ArrayList
System.out.println("The ArrayList contains: " + arrayList);
}
}
In this example, I used an ArrayList
to demonstrate its dynamic behavior. I added elements using add
, removed an element using remove
, and printed the current contents of the list.
Unit 9 - Inheritance
Taught: 10/4
Inheritance allows me to create a new class based on an existing class. The new class inherits attributes and methods from the base class.
// Example of inheritance in Java
class Animal {
String speak() {
return "Animal sound";
}
}
class Dog extends Animal {
@Override
String speak() {
return "Woof!";
}
}
public class InheritanceExample {
public static void main(String[] args) {
Dog myDog = new Dog();
System.out.println(myDog.speak());
}
}
In this example, I defined a base class Animal
with a speak
method. The Dog
class inherits from Animal
and overrides the speak
method. I created an instance of Dog
and called its speak
method.