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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Math class and its different methods
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education