Problem Statement
Given a JavaBean component, you are required to calculate monthly payments for a certain period.
Given class PaymentProcessor:
This class is a JavaBean component.
Mutator and accessor methods for the following properties are defined according to the JavaBean naming conventions, but are not shown here.
private int januaryProfile, februaryProfile, marchProfile, aprilProfile, mayProfile, juneProfile, julyProfile, augustProfile, septemberProfile, octoberProfile, novemberProfile, decemberProfile;
class PaymentProcessor implements Serializable {
/**
* Gets a country code that you can use to construct a Locale object.
*
* @return a lowercase two-letter ISO-639 country code
*/
public String getPaymentLanguage();
/**
* Expresses currency values in the locale corresponding to the
* country code returned by getPaymentLanguage().
*
* Each string is a currency expression with an integer value
* between 0 and 1000000 (one million), inclusive.
*
* @return A collection of strings expressing currency values containing
* between 3 and 100 values, inclusive. Contains no duplicates.
*/
public Collection<String> getPaymentCollection();
}
DEFINITION
You must define a public class MonthlyPayments with public method int[] getValues(int monthNumber, int profile, int minimumPaymentValue).
You must implement getValues as follows:
SET THE PROFILES
Instantiate PaymentProcessor with the default constructor and use the resulting bean to calculate monthly payments.
Set the profile for the month corresponding to monthNumber and all months preceding it in the calendar. For example, if monthNumber is 2, set the profile for February and the preceding month January.
The names of the months in calendar order are: January, February, March, April, May, June, July, August, September, October, November, December.
CALCULATE MONTHLY PAYMENTS
Now call getPaymentLanguage() and use the result to construct a Locale paymentLocale. Pass paymentLocale to NumberFormat.getCurrencyInstance(Locale) to obtain a currency format. Next, call getPaymentCollection() to obtain a collection of strings. Parse each string with the currency format and get the integer value of the resulting Number.
Return an int[] containing the payment values that are greater than or equal to minimumPaymentValue, in the order in which the collection iterates.
Definition
- Class:
- MonthlyPayments
- Method:
- getValues
- Parameters:
- int, int, int
- Returns:
- int[]
- Method signature:
- int[] getValues(int monthNumber, int profile, int minimumPaymentValue)
- (be sure your method is public)
Constraints
- monthNumber will be between 1 and 12, inclusive.
- profile will be between 1 and 8192, inclusive.
- minimumPaymentValue will be between 0 and 1000000 (one million), inclusive.
Examples
4
5173
155000
Returns: {155240, 393112, 840896 }After setting the profile for January, February, March, and April to 5173, we find that getPaymentLanguage() returns "ja", which stands for Japan. If we iterate over the collection returned by getPaymentCollection() and parse each string using the currency format for Japan, we obtain the following values (in order of iteration): 126520, 155240, 393112, 840896. The values that are greater than or equal to 155000 are (in the same order): 155240, 393112, 840896.4
5173
840896
Returns: {840896 }Using the same monthNumber and profile as in the above example, but with a higher minimumPaymentValue, we find that only one value is greater than or equal to the minimum.6
7401
878000
Returns: { }It is possible that no values meet the threshold.12
386
595044
Returns: {684587, 816618 }In this case we are setting the profile for every month in the calendar to 386.3
2902
624735
Returns: {633001, 722945, 723484, 864585, 978552, 716004, 977048, 980397, 717738, 637812, 912416, 841668, 798764, 812079, 882068, 841571, 817127, 675657, 716586, 995554, 841335, 740255, 982217, 970026, 858598, 874127, 852188, 916435, 653375, 949165, 759699, 646129, 877008, 637659, 931074, 896717, 638853, 740045, 985047, 985399 }Here the collection contains 86 values, 40 of which meet the threshold.