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
Do you like classical music? I like classical music. Anyway...let's | |
say we're going to see a concert with a bunch of friends. We want | |
to sit together in a row and there's 5 of us. Furthermore we like to | |
sit close to the front. Cause you know, better view and everything. | |
So given a seating chart, I want you to write a method that will | |
tell us the best row where we can sit. | |
The seating chart is going to be a 2D array like so... |
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
One thing Stanford students get too much of is free T-shirts. There's | |
free T-shirts from career fairs, from your academic department, from | |
dorm events, from campus events, from student groups, etc. etc. etc. | |
So one thing we like to do with our old T-shirts is make quilts out of | |
them! | |
Imagine we had 9 T-shirts. We could stitch them together a 3x3 quilt, | |
where each square unit is a T-shirt. So something like: | |
__________________________________ |
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
Imagine we're a bike shop. We sell bikes. Bikes have a manufacturer, | |
a model name, and a price. So we will represent bikes with the | |
following class: | |
public class Bike | |
{ | |
private int price; | |
private String modelName; | |
private String manufacturer; |
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
Let's write a dice simulator. I want you to write a class that can | |
create an n-sided dice and simulate a dice-roll. In other words, given | |
n, you will create a "dice" with n faces numbered 1...n. To "roll" the | |
dice, you will basically pick a random integer between 1 and n. | |
The class should be able work like this: | |
Dice d1 = new Dice(6); | |
d1.roll(); // Returns random number between 1 and 6 | |
d1.roll(); // Returns another random number between 1 and 6 | |
...etc... |
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
public class MethodPractice | |
{ | |
public static int question1(int a, int b) { | |
return a * b; | |
} | |
public static void question2(int a) { | |
a = 2 * a; | |
} | |
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
public class Practice | |
{ | |
public static void main(String[] args) { | |
// How can you replace the hard coded numbers | |
// with a variable and print out the same thing | |
// as the code below? | |
// | |
// There's more than one way to do this. | |
System.out.println(1); |
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
public class Practice | |
{ | |
public static void main(String[] args) { | |
// How can you replace the hard coded numbers | |
// with a variable? | |
System.out.println(1); | |
System.out.println(2); | |
System.out.println(3); | |
System.out.println(4); |
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.ArrayList; | |
public class Practice | |
{ | |
public static void main(String[] args) { | |
// An example list of words to test against. | |
ArrayList<String> words = new ArrayList<String>(10); | |
words.add("foo"); | |
words.add("bar"); | |
words.add("baz"); |
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
/* Returns all books in this library that are | |
* written by the given author. | |
* | |
* @param author - the author. | |
*/ | |
public ArrayList<Book> getBooksByAuthor(String author) { | |
// Two comments: | |
// | |
// (1) Your solution is pretty close but it returns | |
// a SINGLE book by the given author, not all |
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
public class Book | |
{ | |
private String title; | |
private String author; | |
private String genre; | |
private int numberOfPages; | |
/* Other methods not shown. */ | |
public String getTitle() { |