Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab you will read a list of Strings, followed by two more Strings defining the low and high bounds of a half -
In this lab you will read a list of Strings, followed by two more Strings defining the low and high bounds of a halfopen range. Then you will iterate over the list and, for each String in the list, determine whether it is in the specified range.
The list of Strings is defined by a single integer N followed by N strings. Because the range is not read until after the Strings are read, you will need to store the Strings in an array.
Hint: In section of the text, there is a recipe for reading N doubles into an array that you may find useful.
Given this input:
one two three four five six seven eight nine ten
one ten
your program will print
one is in the range oneten
two is not in the range oneten
three is not in the range oneten
four is not in the range oneten
five is not in the range oneten
six is in the range oneten
seven is in the range oneten
eight is not in the range oneten
nine is not in the range oneten
ten is not in the range oneten
Remember we're comparing Strings here!
Remember that a halfopen range does include the lower bound of the range, but does not include the upper bound. For example, a is in the range ak but k is not.
Using System.out.printf will make your life easier here. Remember that s is the format specifier for a String.
Hint: Don't forget that you cannot compare strings using the and operators. You need to use compareTo
For extra credit, write a less function that takes two Strings and returns true if the first is less than the second, and false otherwise. Then write your code so that main uses only less rather than compareTo This is not as trivial as it sounds! It will take a little thought to figure out how to express other comparisons like in terms of less Wrie in code main.jva
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started