Saturday, April 5, 2025

CST338: Week 2 (Week 10)

 I like that we are using UML and Junit tests. I would like to get reacquainted with them since they are used widely. Even if I don't end up using them regularly, it's best to at least have some exposure.

This HW01 makes me grateful for having done the Coding Bat exercises. I haven't written code in Java for a very long while and it shows. Those exercises were also a good reintroduction to Java HashMaps which we use in HW01. I didn't have a lot of trouble with structuring my solutions but I needed to do a good amount of reading to get more familiar with Java's built-in data structures, error handling (try/catch), and the String class. I also learned about the very handy for each loop. In the past I have most often used C so I appreciate Java and how easy it is to manipulate Strings and text input.

I am glad that Oracle has thoroughly documented Java's built in classes and interfaces. In endsWithPunctuation() I was able to easily access the last character in a string with the built in String.charAt() function. I traversed Strings character by character using String.toCharArray() and a for each loop. I was able to read about these and other methods in the Java documentation. In C, these operations aren't quite as straight forward.

The most interesting/challenging method to implement was addLine(). I needed to convert the input String to an array of words. I was trying to keep the implementation clean and simple but wasn't sure how to clean up the whitespaces in the input. I used String.split() but the problem was that it left a empty string entries in the resulting array. In the end I added a condition to discard any empty Strings while adding to the ArrayList. Given more time I might be able to come up with a better solution but I am happy with the outcome.

No comments:

Post a Comment

CST363: Week 8 (Week 24)

 The three most important things I learned in this course: 1) What databases are and their advantages over for example, a flat file or sprea...