Changes between Version 21 and Version 22 of ControlSystems/SoftwareTeam/Training/GettingStarted/JavaExercises


Ignore:
Timestamp:
Nov 16, 2016, 3:23:31 PM (9 years ago)
Author:
azhang
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/Training/GettingStarted/JavaExercises

    v21 v22  
    2020
    2121
    22 == Another challenge:
     22=== Another challenge:
    2323Write 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
    2424
    2525
    2626== Another challenge: Animal Farm
     27=== Step 1: Abstract Classes
    2728Create an `abstract class` called `Animal` that has a `mass` and a `name`. These should be `private`.
    2829* All animals should have a constructor which gives them a `mass` and a `name` when they are created
     
    5455
    5556
    56 == Animal Farm step 2: Constructor Overloading
     57=== Step 2: Constructor Overloading
    5758* All animals can also be created with only a `mass`.
    5859* If an animal is created without a `name`, it's name is set to `Steve` by default.
     
    8081* How can you get the wingspan of animals[4]?
    8182
    82 == Animal Farm step 3: Method Overloading and Overriding
     83=== Step 3: Method Overloading and Overriding
    8384* 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`.
    8485Hummingbirds are very small, so they will only `eat` a maximum of their own `mass`.
     
    8990From here on out, run whatever code you need in `Farm` to check to make sure your code works the way it is expected to.
    9091
    91 == Animal Farm step 4: Enums
     92=== Step 4: Enums
    9293* Create an `enum` called `State`, which can be `TAMED`, `PARTIALLY_TAMED`, or `WILD`
    9394* `Cat` and `Dog` all have a `State`. Hummingbirds do not
     
    9798* `Dog` can be `tame`, which makes them more tamed (`WILD` -> `PARTIALLY_TAMED`, `PARTIALLY_TAMED` -> `TAMED`, `TAMED` -> `TAMED`)
    9899
    99 == Animal Farm step 5: Static
     100=== Step 5: Static
    100101* `Animal` has a `static int` called `population`, which starts at `0` and increases by `1` every time an animal is created
    101102* `Animal` has a `static getPopulation` method which returns the total number of animals created
    102103* When two Animals `meet`, the more massive one eats the one with less mass. This should be a `static` method in `Animal`
    103104
    104 == Animal Farm step 6: Interfaces
     105=== Step 6: Interfaces
    105106* Create an `interface` called `Building`
    106107* A building must be able to `collapse`
    107108* A building must be able to `store` an object
    108109
    109 == Animal Farm step 7: Lists, Generics
     110=== Step 7: Lists, Generics
    110111* A `Farm implements Building`
    111112* A `Farm` has a `List` of `Animal`
     
    117118  * Warning: Clearing a List is not the same as setting it to null.
    118119
    119 == Review: Deck of Cards (Enums, Lists)
     120=== Review: Deck of Cards (Enums, Lists)
    120121Create 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.
    121122
    122 == Review: Creatures (Inheritance, Static)
     123=== Review: Creatures (Inheritance, Static)
    123124Create 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).
    124125
    125 == Deck of Cards step 2:
     126=== Deck of Cards step 2:
    126127Program 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.
    127128
    128 == Creatures step 2:
     129=== Creatures step 2:
    129130Program 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.