Reading from Keyboard, Printing to Display

One principle of good software design is to create the software so that it can be modified easily in the future. In this assignment you will be using that same kind of statements that you have used in the past to do I/O, but we would like you to design your program so that it could be easily modified (hypothetically) at some later date. (This modification won't actually take place, but in order to motivate a good design, let's assume that it might)

Imagine that your program will be modified in the future so that instead of doing I/O as we learned in class, a Graphical User Interface (GUI) will be implemented. (NOTE: You shouldn't write a GUI for this assignment, unless you really want to. If you do, you won't receive any extra marks.) The GUI might display nice images of a backyard and bones, and let you click on grid positions with the mouse, for example.

The question is this: How do we best structure our program so that the program could be changed at a later date to use a GUI? The answer is that we should put all our I/O statements in a single class. That class will just do I/O and nothing else. In that way, a GUI could be implemented at a later date by just replacing that one class with a class that implements the GUI.

In this assignment you must put all statements that read from the keyboard or write to the display in a number of methods of your choosing that belong to a single class. Whenever you want to read from the keyboard or write to the display, you will have to call a method in this input/output class. There will be no I/O statements anywhere else in your program.

More specifically, when you want to print information to the screen, you will have to call a method in your input/output class and send that information as an argument to that method. That method will then print information to the screen. When you want to read something from the keyboard, you will have to call a method in the input/output class which reads from the keyboard and returns the information to the calling method as a return value.

The upshot is that all statements that read from the keyboard and write to the display must be in one class, and you shouldn't be writing a GUI for this assignment. (no bonus marks or penalty if you do)

The user of the program will have to specify a row number and a column number in order to specify a position on the grid. You must use two calls of the method readLine() (or any other suitable method) to input this information: one for the (integer) row number and one for the (integer) column number. You are free to read these as strings, or characters, or whatever you like. In the case of a string or a character, you will most likely want to convert the input value to an integer.