- Designing a class
- Creating objects
- Getters and setters
- Constructors
- compareTo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
public class ArrayListTraversalDemo { | |
public static void main(String[] args) { | |
ArrayList<Integer> outcomes = new ArrayList<Integer>(Arrays.asList(10,40,10,10,60,10)); | |
System.out.println("10 occurs "+countOccurrences(outcomes, 10)+" times in the list "+outcomes); | |
System.out.println(outcomes+" in ascending order? "+isAscending(outcomes)); | |
} | |
public static int countOccurrences(ArrayList<Integer> list, int target) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class GrowingArray { | |
public static void main(String[] args) { | |
int[] data = new int[2]; //initial size is 2 | |
int nItems = 0; //no items stored yet | |
for(int i=0; i < 10; i++) { //we'll add a total of 10 items | |
if(nItems >= data.length) { //if we go out of bounds |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
public int data; | |
public Node next; | |
public Node(int _data, Node _next) { | |
data = _data; | |
next = _next; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package operationsOnPrimitiveTypes.solutions; | |
import static org.junit.jupiter.api.Assertions.*; | |
import org.junit.jupiter.api.Test; | |
public class DebuggingInt { | |
/** | |
* | |
* @param data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package operationsOnPrimitiveTypes.solutions; | |
import static org.junit.jupiter.api.Assertions.*; | |
import org.junit.jupiter.api.Test; | |
public class DebuggingBoolean { | |
/** | |
* | |
* @param data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.jupiter.api.Assertions.*; | |
import org.junit.jupiter.api.Test; | |
class Client { | |
/** | |
* | |
* @param n | |
* @return true if n is an even number, false otherwise | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static org.junit.Assert.*; | |
import java.util.Arrays; | |
import org.junit.jupiter.api.Test; | |
public class ArrayRecursion { | |
/** | |
* | |
* @param data: array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//demo video of output at https://www.youtube.com/watch?v=VhMAgLKTz7U | |
import java.util.*; | |
int level = 2; //1: 4 by 4, 2: 9 by 9, 3: 16 by 16 | |
boolean numerical = true; //change to false for 'A', 'B', 'C', ... | |
char start = numerical ? '1' : 'A'; | |
final int MARGIN = 30; | |
int n = level+1; |