Created
August 18, 2011 15:07
-
-
Save brycethomas/1154251 to your computer and use it in GitHub Desktop.
Apples simulator - amended main method and toString() 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
// prints out something like "Apple 27 (GRANNY_SMITH, 3)" | |
public String toString() { | |
return String.format("Apple %d (%s, %s)",size,type,batchNumber); | |
} | |
public static void main(String[] args) { | |
Random random = new Random(); // this is the line missing from the workshop pdf | |
final int SIZE = random.nextInt(5) + 1; | |
Apple[] apples = new Apple[SIZE]; // a randomly sized apples array | |
for (int i = 0; i < SIZE; ++i) { | |
AppleType[] types = AppleType.values(); | |
int whichType = random.nextInt(types.length); | |
int size = random.nextInt(20) + 10; | |
apples[i] = new Apple(size, types[whichType]); // create random apples | |
} | |
System.out.println("New apples: " + Arrays.deepToString(apples)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment