You have two problems with this code, one is that you are missing a brace, which you've already found. The other is that, being a utility class with only static methods and no member variables, a toString() method no longer has any meaning. There are no members to print. If you want something printed you'd do it in the method that calls decode(). You could slip a print into decode() but I wouldn't suggest it, that would violate the singleness of purpose that decode() has which is to decode a letter.

I attempted to ask this question several times across several of my posts, but each time it was passed over in favor of helping me fix other issues. If I'm remembering correctly, I've asked a separate three times, which I can find if needed. While I do appreciate the help with my other issues, this is a issue and I felt that maybe posting it separately would get the help I needed. The title of my other thread was also "Final line of code not returning proper values," and I felt that maybe asking this question separately may help others trying to find a solution to a similar issue.

I will not duplicate my questions in the future, but I would appreciate it if you close this thread, and not the thread on which I was actively receiving help with a separate issue, so I can continue working.

Jeremiah Waters

Ranch Hand

Posts: 61

posted 3 months ago

Sorry, I didn't realize that you were replying on this forum! I'll try that!

Thank you! I'm working on your suggestions now, but is there any way that you can answer my original question for this thread? It pertains to both the code used in my original thread and this one; I'm just confused on how to format the additional test cases with the imported scanner-

Jeremiah Waters wrote: I want to add some more test cases to the code below, but I'm not quite sure how to format those additional test cases. Can anyone help?

Sorry for the confusion. I'm trying to get it to where it'll ask for me to enter several letters (sort of an "enter letter" then output response, "enter letter" then output that response, on and on). I didn't explain that as clearly as I could've, sorry.

[SOAPBOX]
This is why I get frustrated with schools not keeping up to date with modern development practices being used in the industry. If I were teaching, I'd want to introduce unit tests and unit testing to students. That way, it would lead them to object-oriented programming sooner, which I don't think is that far of a stretch from what they're doing with all procedural static methods. It's just one less thing they will need to unlearn later. The other problem is that they never seem to progress to a point where they actually need to unlearn that stuff. They seem to be finishing their Java courses still writing freaking static methods all the time. And writing big blocks of code, too. Sigh.

I don't buy any argument along the lines of "Unit tests are too complicated for students." I have to call BS on that. Martin Odersky's Scala course on Coursera.org uses unit tests from Day 1 and as far as I recall, there was no requirement for students to already know SBT or testing framework (ScalaTest?) in order for them to use those unit tests and verify their assignments.

If anything, I would start students off with a pre-written set of tests that they need to provide implementations for. Once they get the tests to all pass, they should be confident that their code works. They don't need to understand the full workings of the unit tests. They just need some basic instructions on how to run the tests.

I found this to be a pretty effective way to introduce students to tests even if they had never seen a test before.

Thank you for this suggestion! I may try this approach to my code after I complete it in its current form. However, I'm still looking for assistance with my original question:

Jeremiah Waters wrote:I want to add some more test cases to the code below, but I'm not quite sure how to format those additional test cases. I'm trying to get it to where it'll ask for me to enter several letters (sort of an "enter letter" then output response, "enter letter" then output that response, on and on). Can anyone help?

Jeremiah Waters wrote:Sorry for the confusion. I'm trying to get it to where it'll ask for me to enter several letters (sort of an "enter letter" then output response, "enter letter" then output that response, on and on). I didn't explain that as clearly as I could've, sorry.

If you don't want to mess with unit tests like those that I showed above, you will need to create a loop so that those statements that you're executing one time will be executed multiple times by the loop. The problem with your approach is that you're doing it manually. That is slooooow. I'm a lazy programmer and if I can do it in a more automated fashion, I would spend time writing code to do all the testing for me, even if I'm not using an automated unit testing framework like JUnit.

Jeremiah Waters wrote:Thank you all for your help! I was misreading an error and resolved the issue! I will take everyone's input to heart when reworking my code to be more efficient; thank you for your time!!

Rather than make it more efficient, rework the code so that it's clearer and smaller. There is a lot of redundant code in your final version and there are many things you can do to make it clearer and cleaner.

Just as an example, consider this equivalent version of your isUpper() method:

This code works exactly the same as your code, except it's one line and it's much clearer because it uses char literals instead of the equivalent numeric values. You can do similar things for your isLower() and isNumber() methods.

That reminds me of what we used to write when I did O level maths: 10 &leq; x &leq; 20. I know no programming language where that sort of thing will compile; the nearest I know is. . . which is Forth, but its semantics is totally different.

. . .. . .

It all depends on whether you look at the code and see it or hear it.

If A is less than the char and the char is less than Z

versus

If the char is greater than A and the char is less than Z

I know I should say, “less than or equal”.

. . . making it purely intent-ful would help. . . .

That modularises the code, so it is better in procedural coding, or OO, or functional.

All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad: