Week 10: CST338 Week 2: More and More Java
This week, I learned about Java's equals(), toString(), and @Override methods, as well as inheritance. The equals() method is essential for comparing object contents rather than references, while toString() provides a string representation of an object. The @Override annotation ensures that subclass methods adhere to the parent class's method signatures. We explored inheritance, which allows a class to reuse code from another class or interface. Understanding these concepts helps in writing better and maintainable Java code.
I also worked on Histogram.java, and it was quite a fun experience. The most challenging part was the display() function, where I spent some time to figure it out. Printing the histogram correctly was tough. Seeing the output work correctly was very rewarding, though!.
At one point, the display() method correctly displayed the output for all processed .txt files but encountered an error with tq6.txt. This was because one of the letters had a double-digit count (10 occurrences). I added an additional if statement to handle this issue..
Additionally, I also worked on the first two parts of Project 1.
Some handy format specifiers in Java:
- %s for a string
- %d for an integer
- %n for a platform-independent newline character
- %c for a character
Comments
Post a Comment