Commit a14f2c73 authored by Adam Blank's avatar Adam Blank
Browse files

Add Lecture01 Skeleton

parents
No related merge requests found
Showing with 67 additions and 0 deletions
+67 -0
public class DoggieAnimation {
public static void main(String[] args) {
// Setup Canvas and Scale
StdDraw.setCanvasSize(1024, 768);
StdDraw.setScale(-1024, 1024);
IntBag bag = null;
// Add each picture once
for (int i = 1; i <= 10; i++) {
bag.add(i);
}
// Add my favorite picture many times
for (int i = 0; i < 10; i++) {
bag.add(3);
}
while (true) {
// get next picture name
String pic = "pictures/hopper" + bag.pick() + ".jpg";
// draw it
StdDraw.picture(0, 0, pic);
// pause
StdDraw.pause(2000);
System.out.println(pic);
}
}
}
/**
* An IntBag represents a multiset of integers between min and max.
* That is, each number between min and max can occur some non-negative
* number of times in a particular IntBag.
*/
public class IntBag {
// constructors in java are like __init__ in python
public IntBag(int min, int max) {
}
/**
* Adds one instance of value to this IntBag.
* @param value the value to be added
*/
public void add(int value) {
}
/**
* Returns true when the bag has no instances of any elements
* and false otherwise.
* @return true iff the bag is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Chooses (but does not remove) a uniformly random element from this
* IntBag in proportion to how many elements exist for each number.
* @return the element picked from the bag
*/
public int pick() {
return -1;
}
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment