Problem Statement
People can type different keys at different rates. For example, some people have theorized that it is faster to type keys on the home row because you don't have to move your fingers as much (the home row is the middle row, which is typically where people rest their fingers when not actively typing). As a result, different key layouts have been proposed to take advantage of this. Dvorak, for example, places all of the vowels and commonly used consonants on the home row.
Your task is to create a class Typing with a method speed that takes two int[] as parameters. The first one, rates, will contain the rates at which each key can be typed, in strokes per minute. The second int[], freq, will contain the amount of time spent typing each character as a percentage of total time. Your task is to write a class Typing, with a method speed that, given a int[] of typing rates for individual keys, and a int[] of frequencies for each key, returns the overall typing rate, rounding down.
Definition
- Class:
- Typing
- Method:
- speed
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int speed(int[] rates, int[] freq)
- (be sure your method is public)
Notes
- Each element of rates corresponds to the element of freq with the same index.
- If the overall rate is not an integer, simply truncate (round down) the fraction.
Constraints
- rates and freq have between 1 and 50 elements, inclusive, and both contain the same number of elements.
- each element of rates is between 1 and 10,000, inclusive
- each element of freq is between 0 and 100, inclusive
- the sum of all the elements of freq is 100
Examples
{10,20}{50,50}Returns: 15
Since half of the time is spent typing at a rate of 10, and the other half is spent at a rate of 20, the overall rate is 15.{10000}{100}Returns: 10000
Since 100% of the typing occurs at a rate of 10,000 strokes per minute, the overall speed is 10,000 strokes per minute.{3,4,5,6,7}{10,20,30,40,0}Returns: 5
{10,10,13}{34,33,33}Returns: 10