Practice pieces


Methods: calculator

Ok, so here's the simplest way of doing these tasks:

Part 1: Calculator1.java (note how few lines are needed if we keep from making needless labels)
Part 2: Calculator2.java and IntCalc.java


 

Can you finish this off by:

1) Adding a DoubleCalc class as well?

2) Changing IntCalc so it has static methods, and call them straight from the class definition (within the main class; as we would if we used Math.random()).

Note that for (2), if you write IntCalc a empty default constructor, and set it as private, people will have to use the methods straight from the class, because they won't be able to make objects from the class.