Changes between Version 21 and Version 22 of ControlSystems/SoftwareTeam/Training/GettingStarted/JavaExercises
- Timestamp:
- Nov 16, 2016, 3:23:31 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/Training/GettingStarted/JavaExercises
v21 v22 20 20 21 21 22 == Another challenge:22 === Another challenge: 23 23 Write a high-low guessing game; have a person think of the number, and have the computer try to guess it. After each guess, the human will tell the computer whether it's higher or lower 24 24 25 25 26 26 == Another challenge: Animal Farm 27 === Step 1: Abstract Classes 27 28 Create an `abstract class` called `Animal` that has a `mass` and a `name`. These should be `private`. 28 29 * All animals should have a constructor which gives them a `mass` and a `name` when they are created … … 54 55 55 56 56 == Animal Farm step 2: Constructor Overloading57 === Step 2: Constructor Overloading 57 58 * All animals can also be created with only a `mass`. 58 59 * If an animal is created without a `name`, it's name is set to `Steve` by default. … … 80 81 * How can you get the wingspan of animals[4]? 81 82 82 == Animal Farm step 3: Method Overloading and Overriding83 === Step 3: Method Overloading and Overriding 83 84 * All animals can also `eat` other `Animal`, which increases their `mass` by the `mass` of the `Animal` they ate, and sets the `mass` of the `Animal` they ate to `0`. 84 85 Hummingbirds are very small, so they will only `eat` a maximum of their own `mass`. … … 89 90 From here on out, run whatever code you need in `Farm` to check to make sure your code works the way it is expected to. 90 91 91 == Animal Farm step 4: Enums92 === Step 4: Enums 92 93 * Create an `enum` called `State`, which can be `TAMED`, `PARTIALLY_TAMED`, or `WILD` 93 94 * `Cat` and `Dog` all have a `State`. Hummingbirds do not … … 97 98 * `Dog` can be `tame`, which makes them more tamed (`WILD` -> `PARTIALLY_TAMED`, `PARTIALLY_TAMED` -> `TAMED`, `TAMED` -> `TAMED`) 98 99 99 == Animal Farm step 5: Static100 === Step 5: Static 100 101 * `Animal` has a `static int` called `population`, which starts at `0` and increases by `1` every time an animal is created 101 102 * `Animal` has a `static getPopulation` method which returns the total number of animals created 102 103 * When two Animals `meet`, the more massive one eats the one with less mass. This should be a `static` method in `Animal` 103 104 104 == Animal Farm step 6: Interfaces105 === Step 6: Interfaces 105 106 * Create an `interface` called `Building` 106 107 * A building must be able to `collapse` 107 108 * A building must be able to `store` an object 108 109 109 == Animal Farm step 7: Lists, Generics110 === Step 7: Lists, Generics 110 111 * A `Farm implements Building` 111 112 * A `Farm` has a `List` of `Animal` … … 117 118 * Warning: Clearing a List is not the same as setting it to null. 118 119 119 == Review: Deck of Cards (Enums, Lists)120 === Review: Deck of Cards (Enums, Lists) 120 121 Create a Deck of Cards. Each Card has a value Ace through King, and a suit. You can draw cards from the top of the deck, do a perfect riffle shuffle (split the deck in half and alternate cards) of the deck, and print out all the cards in the deck. Overriding the `toString` method will be very helpful. 121 122 122 == Review: Creatures (Inheritance, Static)123 === Review: Creatures (Inheritance, Static) 123 124 Create a Garden of Plants. Plants and Animals are both Creatures. Make up some methods that you think are suitable for each, and create them (ex. What do all creatures do the same? What do all creatures do differently? What do only specific creatures do?). Make sure you include static variables and methods (ex. list of all creatures ever created). 124 125 125 == Deck of Cards step 2:126 === Deck of Cards step 2: 126 127 Program a card game (war, go fish, etc.) using your deck of cards. Create any methods you will need for your game, and see how much you can optimize your game. 127 128 128 == Creatures step 2:129 === Creatures step 2: 129 130 Program a game using all your creatures classes (ex. text based agar.io). Create whatever methods and/or classes you will need, and try to keep your code as simple as possible.