Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: XXXXXXXXXXpizza XXXXXXXXXXAlso suppose that you have a particular item that you know the...




Suppose that a Scanner object contains a bunch of tokens all on a single line separated by spaces. For example: 100.5 30.4 pizza 56.8 1000.3 8.2 Also suppose that you have a particular item that you know the price of. Let’s use the following example: Kindle: 99.99 Write a static method: public static double priceIsRight(Scanner s, double price)that takes a Scanner and an item price as parameters and returns the bid that is closest to the item price but not greater than the item price. If all bids are greater than the price, return 0.0. If there are no bids (Scanner is empty) return 0.0. You can assume the Scanner is not null. In the above example. 56.8 should be returned, since it is the number that is closest to 99.99 but not over 99.99. Notice that there may be some invalid tokens in the Scanner's input. The above example has pizza as one of its tokens, which is clearly not a valid bid. Your method should throw these tokens away and not consider them as bids. It is probably easiest to test your method by creating a Scanner with a String instead of System.in.

Tests to
include in your main method:

  • Test the above example with “100.5 30.4 pizza 56.8 1000.3 8.2” as the tokens and 99.99 as the price. The result should be 56.8.

  • Test a Scanner that is created using an empty String as the source and any number for the price. The result should be 0.0.

  • Include a test where all the bids are greater than the price. The result should be 0.0.


May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here