Problem Statement
There are several internet book searching engines which search for the book you want on multiple bookselling sites, and return the search results. You have been asked to design such an engine which also searches internationally. This adds the extra step of converting the prices found from foreign currency to United States dollars (USD).
Create a class Booksearch that contains the method search which takes as arguments a int[] prices which represents the foreign prices found for a book, and a int[] rates which represents the conversion rate from the specific foreign currencies to USD. The method should return the price of the cheapest book found in terms of USD.
The price of the kth element of prices will be in the same currency as the kth element of rates, and the value of each element of rates will be the amount of that currency equivalent to 1 USD.
Return the cheapest book's price in USD, rounded down to the nearest dollar. To do this, divide the foreign price by the exchange rate, and round down. Notice that this value may be 0.
Definition
- Class:
- Booksearch
- Method:
- search
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int search(int[] prices, int[] rates)
- (be sure your method is public)
Constraints
- prices will contain between 1 and 50 elements, inclusive.
- each element of prices will be between 1 and 10000, inclusive.
- rates will contain between 1 and 50 elements, inclusive.
- each element of rates will be between 1 and 1000, inclusive.
- prices and rates will have the same number of elements.
Examples
{40,20,10}{10,10,10}Returns: 1
Each book is in a currency that has the same value relative to the USD, and the book prices in USD are 4, 2, and 1 respectively.{40,20,10}{4,2,1}Returns: 10
This time all the books cost 10 USD.{40,20,10}{8,2,1}Returns: 5
The prices in USD are 5, 10, and 10 respectively.{102, 205, 152, 3525, 5253}{10, 20, 15, 360, 610}Returns: 8
Remember that fractions of dollars get rounded down.{500, 500, 500}{15, 25, 35}Returns: 14