This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
Guys I was trying something out, I got my code to work 100% perfectly, but I wanna know how can I make it more elegant. So I thought why not instead of repeating same the 2 lines code three times (in case the user entered "Yes") why not just call a method which will do the same job ? and that's where I got stuck !
I guess I'm good in writing the main() method only, but when it comes to combining other methods with each others and calling this method from there and stuff I pretty much don't know what to do : (
So this is my code, pretty simple stuff, just trying to practice on different things like loops and if statements, anyways please advise ..
And also, is there anyway to make the equals() method consider the "yes, Yes & YES" all the same without detailing them as I did ? if there is a ways, is it suitable for me as a beginner to learn it at this stage or should I just leave it for later on ?
No, you are not doing it right at all. I am surprised if you got that to compile at all. You were told to look for equals methods, so why did you go for compareTo? Back to the String class documentation, find the methods summary, and have another look.
Campbell Ritchie wrote:No, you are not doing it right at all. I am surprised if you got that to compile at all. You were told to look for equals methods, so why did you go for compareTo? Back to the String class documentation, find the methods summary, and have another look.
Well, who said I was able to compile it ? lol !
Anyways I got it to work now, when rob told me to look for other methods, my eyes fell on the compareToIgnoreCase method and from the sound of it I thought this is it. Apparently I was wrong and I was supposed to use equalToIgnoreCase which I didn't know about until you gave me that link. So thank you guys : ).