This file contains hidden or 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
/* Let's pretend we're building a game, which has a physics | |
* simulation and a renderer. We're expecting to have a | |
* sufficiently large collection of entities that updating in a | |
* functional/immutable style is too expensive, but we still want | |
* to avoid allowing mutation where it's not strictly required. | |
* | |
* To this effect, note how `physics` takes a list of MutableEntity, | |
* but `render` takes Entity instead. The physics simulation is | |
* expected to mutate the entities (to update their (x,y) position | |
* according to whatever the simulation wants to do), but rendering |
This file contains hidden or 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
import java.util.Scanner; | |
public class AutoCalc { | |
/* It's conventional that field names are in camelCase, so I changed that. | |
* | |
* The private keyword means only this class can look at these values. Here, | |
* declaring the field as 'static' means that it's a class field, rather than | |
* an instance field. The two x and y values are specific to one particular |