Hello,
I am getting NullPointerException because my Tape() constructor is not correct.
I welcome any hints and suggestion regarding this or anything else that does not look right.
Thank you.
There are 3 classes: Cell, Tape, and TapeTest which has main()
The idea was to implement "initially consists of a single cell. The cell should contain a blank space, and the current cell pointer should point to it."
I suppose if it is a new Cell containing a char that would have a default value of '\u0000' already so it is not necessary to initialize it.
Igor Mechnikov wrote:The idea was to implement "initially consists of a single cell. The cell should contain a blank space, and the current cell pointer should point to it."
Then why assign the value of NULL to the char? Why not
Also something that should be done is encapsulation... If you are changing variables in another class you should be using accessor methods to do so. I.E.
While what you are doing will work it is in no way proper.
Igor Mechnikov wrote:The idea was to implement "initially consists of a single cell. The cell should contain a blank space, and the current cell pointer should point to it."
Then why assign the value of NULL to the char? Why not
While what you are doing will work it is in no way proper.
Thank you very much. I actually looked up the default value for char, did not know I could have used ' '. little light bulb flickers.
As far as encapsulation, I was given Cell and TapeTest classes and had to create Tape.
However, It makes too much sense that methods having to do with Cell ought to be where they belong.
This way Tape methods could go to the currentCell and then implement Cell methods.
Igor Mechnikov wrote:As far as encapsulation, I was given Cell and TapeTest classes and had to create Tape.
Gotcha, was kinda curious what code if any you had been provided.
Regardless, adding that in when it wasn't required simply to practice proper OO coding SHOULD (I'd hope) impress/please the instructor.
Igor Mechnikov wrote:As far as encapsulation, I was given Cell and TapeTest classes and had to create Tape.
Gotcha, was kinda curious what code if any you had been provided.
Regardless, adding that in when it wasn't required simply to practice proper OO coding SHOULD (I'd hope) impress/please the instructor.
Also...
could be done as...
I wish I had an instructor who evaluated my work (story for another day)
I changed constructor to
and Eclipse no longer complains about it,
Now, the problem becomes my for loop
since index is initialized to 0 I am getting more NullPointerExceptions