Question: I need help with this ASAP! IN JAVA Please and thank you. When comparing strings with the built-in method compareTo, the comparison is not always

I need help with this ASAP!

IN JAVA

I need help with this ASAP! IN JAVA Please and thank you.

When comparing strings with the built-in method compareTo, the comparison is not

Please and thank you.

When comparing strings with the built-in method compareTo, the comparison is not always satisfactory. For example, "file10". compareTo ("file2") returns a negative value, indicating that "file10" should come before "file2", even though we would prefer it to come afterwards. Produce a method int numCompare (String str1, String str2) that, when comparing two strings that are identical except for a positive integer at the end, compares the integers. For example, numCompare ("file12", "file2") should return a positive number, and numCompare ("file7", "file11") should return a negative number. numCompare ("file2", "doc12") should return a positive number, since the strings don't match and will therefore be compared on the regular basis that compareTo uses. Note that we say it should return a "positive number" or "negative number" because the value compareTo returns can be something other than 0,1 or 1. As long as the sign of the number returned is correct, your solution is valid. Write and use a helper method int findNumberposition (String str) that returns the starting position of the number, or 1 if there is none. We will not assess you on the inclusion of a main method that tests this method or whether you use the Scanner for input, but you should, of course, use a main method to somehow test that your numCompare produces the correct output for your own sake

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!