Changes between Version 2 and Version 3 of ControlSystems/SoftwareTeam/Training/GettingStarted/JavaExercises


Ignore:
Timestamp:
Nov 14, 2016, 8:07:43 PM (9 years ago)
Author:
azhang
Comment:

More formatting

Legend:

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

    v2 v3  
    1111After each guess, the human will tell the computer whether it's higher or lower
    1212
     13
    1314Another challenge: Animal Farm
    1415Create an `abstract class` called `Animal` that has a `mass` and a `name`
    15  -All animals should have a constructor which gives them a mass and a name when they are created
    16  -All animals can eat an amount, which increases their mass by amount
    17  -All animals can also move a distance, which decreases their mass by distance
    18  -Everybody can use getName to get the name of an animal
    19  -Everybody can use getMass to get the mass of an animal
    20 -All animals can speak, but each type of animal speaks differently
    21 Create a class called Cat that extends Animal
    22  -When a cat speak, it prints Meow!
    23 Create a class called Dog that extends Animal
    24  -When a dog speak, it prints Woof!
    25 Create a class called Farm
    26  -The Farm has a main method
    27  -In the main method, the Farm creates a Cat with a mass of 12.2 named Cloud
    28  -In the main method, the Farm creates a Dog with a mass of 15.4 named Spot
     16  -All animals should have a constructor which gives them a `mass` and a `name` when they are created
     17  -All animals can `eat` an `amount`, which increases their `mass` by `amount`
     18  -All animals can also `move` a `distance`, which decreases their `mass` by `distance`
     19  -Everybody can use `getName` to get the name of an animal
     20  -Everybody can use `getMass` to get the mass of an animal
    2921
    30 In the main method, the Farm will print the names of both animals and their masses.
    31  -Ex. Spot is a Dog with a mass of 15.4.
    32 Then, Cloud will eat 0.2, move 0.8, and speak.
    33 Spot will then eat 0.4,  move 0.6, and speak.
    34 Farm will print the names of both animals and their masses once again.
     22Create a class called `Cat` that `extends Animal`
     23  -When a cat `speak`, it prints `Meow!`
    3524
    36 You will probably get weird numbers like 15.200000000001. This is imprecision with floating point numbers, and is normal.
     25Create a class called `Dog` that `extends Animal`
     26  -When a dog `speak`, it prints `Woof!`
     27
     28Create a class called `Farm`
     29  -The `Farm` has a `main` method
     30  -In the `main` method, the `Farm` creates a `Cat` with a `mass` of `12.2` named `Cloud`
     31  -In the `main` method, the `Farm` creates a `Dog` with a `mass` of `15.4` named `Spot`
     32
     33In the `main` method, the `Farm` will print the names of both animals and their masses.
     34    -Ex. `Spot is a Dog with a mass of 15.4.`
     35Then, `Cloud` will `eat` `0.2`, `move` `0.8`, and `speak`.
     36`Spot` will then `eat` `0.4`,  `move` `0.6`, and `speak`.
     37`Farm` will print the names of both animals and their masses once again.
     38
     39You will probably get weird numbers like 15.200000000001. This is imprecision with floating point numbers, and is normal