| 1 | http://www.ntu.edu.sg/home/ehchua/programming/java/j2a_basicsexercises.html |
| 2 | Recommended exercises: |
| 3 | SumAndAverage |
| 4 | CheckerBoard |
| 5 | fibonacci |
| 6 | Bin2Dec |
| 7 | GradeStatistics |
| 8 | |
| 9 | Another challenge: |
| 10 | Write a high-low guessing game; have a person think of the number, and have the computer try to guess it |
| 11 | After each guess, the human will tell the computer whether it's higher or lower |
| 12 | |
| 13 | Another challenge: Animal Farm |
| 14 | Create 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 |
| 16 | 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(edited) |
| 21 | -All animals can speak, but each type of animal speaks differently |
| 22 | Create a class called Cat that extends Animal |
| 23 | -When a cat speak, it prints Meow! |
| 24 | Create a class called Dog that extends Animal |
| 25 | -When a dog speak, it prints Woof! |
| 26 | Create a class called Farm |
| 27 | -The Farm has a main method |
| 28 | -In the main method, the Farm creates a Cat with a mass of 12.2 named Cloud |
| 29 | -In the main method, the Farm creates a Dog with a mass of 15.4 named Spot |
| 30 | |
| 31 | In the main method, the Farm will print the names of both animals and their masses. |
| 32 | -Ex. Spot is a Dog with a mass of 15.4. |
| 33 | Then, Cloud will eat 0.2, move 0.8, and speak. |
| 34 | Spot will then eat 0.4, move 0.6, and speak. |
| 35 | Farm will print the names of both animals and their masses once again. |
| 36 | |
| 37 | You will probably get weird numbers like 15.200000000001. This is imprecision with floating point numbers, and is normal |