This file contains 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 InheritancePractice | |
{ | |
public static abstract class Vehicle | |
{ | |
public int maxSpeed; // In MPH | |
public int acceleration; // In 0-60MPH secs | |
public Vehicle(int maxSpeed, int acceleration) { | |
this.maxSpeed = maxSpeed; | |
this.acceleration = acceleration; |
This file contains 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.*; | |
class ReadingPractice | |
{ | |
/* What is the return value of |mystery("hi")|? | |
* | |
* (A) hi | |
* (B) hi5 | |
* (C) hi55 | |
* (D) mn |
This file contains 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.*; | |
class Errors | |
{ | |
/* Adds the given value to everything in the ArrayList. | |
* | |
* This AddToAll method does not work correctly. Explain | |
* why. | |
* | |
* Which of the following replacements for line 19 will fix the method? |
This file contains 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.*; | |
class MoreArrayListTest | |
{ | |
public static void main(String[] args) | |
{ | |
// Run all the tests. | |
testNormalize(); | |
testShuffle(); | |
testRemoveDuplicates(); |
This file contains 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 MoreArrayList | |
{ | |
// Think! | |
// | |
// What are the repeatable units of work? | |
// This is what goes in the for loop. | |
// | |
// If you see the keyword "every" or "for every X do Y" |
This file contains 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
public class ArrayListTest | |
{ | |
public static void main(String[] args) | |
{ | |
MyArrayList list = new MyArrayList(5); | |
for (int i = 0; i < 1000; i++) { | |
list.add(i); | |
} |
This file contains 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 Solution | |
{ | |
public static class TicTacToe | |
{ | |
/* | |
* This board will represent all the plays made in | |
* the game so far. | |
* |
This file contains 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
public void removeCol(int col) { | |
for (int i = entries.size() - 1; i >= 0; i--) { | |
SparseArrayEntry entry = entries.get(i); | |
if (entry.getCol() > col) { | |
// Fix the column number for this item because it's in a column | |
// to the right of the column we're removing | |
SparseArrayEntry fixedEntry = new SparseArrayEntry(entry.getRow(), | |
entry.getCol() - 1, | |
entry.getValue()); | |
entries.set(i, fixedEntry); |
This file contains 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
Let's write (part of) a tic-tac-toe game! | |
Let's suppose the game board is represented using a 3x3 2D array of | |
integers like this: | |
______________________ | |
| | | | | |
| 1 | O | O | | |
|______|______|______| | |
| | | | |
This file contains 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
Let's imagine you're a really forgetful person, so you decide to make | |
a to-do list program to help you remember things. | |
Everything that you want to do has a description and a time. For | |
example, uh..."buy eggs at Costco on Wednesday". So let's represent | |
things that you want to do with the following class: | |
public class ThingToDo | |
{ | |
private String description; // Ex. "Buy eggs at Costco" |
NewerOlder