Answered step by step
Verified Expert Solution
Link Copied!

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 half-open 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 1.2 of the text, there is a recipe for reading N doubles into an array that you may find useful.)
Given this input:
10
one two three four five six seven eight nine ten
one ten
your program will print
one is in the range [one,ten).
two is not in the range [one,ten).
three is not in the range [one,ten).
four is not in the range [one,ten).
five is not in the range [one,ten).
six is in the range [one,ten).
seven is in the range [one,ten).
eight is not in the range [one,ten).
nine is not in the range [one,ten).
ten is not in the range [one,ten).
(Remember, we're comparing Strings here!)
Remember that a half-open range does include the lower bound of the range, but does not include the upper bound. For example, "a" is in the range ["a","k"), 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AutoCAD Database Connectivity

Authors: Scott McFarlane

1st Edition

0766816400, 978-0766816404

More Books

Students also viewed these Databases questions

Question

Why are eicosanoids called local mediators rather than hormones?

Answered: 1 week ago

Question

In Java parameter variables must be declared with their data type

Answered: 1 week ago