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.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 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 Solutions | |
{ | |
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 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() { |
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
/* 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 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 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 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 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 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 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; |
OlderNewer