Java tutorial
//package com.java2s; /* * Copyright (c) 2015, MasterCard International Incorporated and/or its * affiliates. All rights reserved. * * The contents of this file may only be used subject to the MasterCard * Mobile Payment SDK for MCBP and/or MasterCard Mobile MPP UI SDK * Materials License. * * Please refer to the file LICENSE.TXT for full details. * * TO THE EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS", WITHOUT * WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NON INFRINGEMENT. TO THE EXTENT PERMITTED BY LAW, IN NO EVENT SHALL * MASTERCARD OR ITS AFFILIATES BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ import java.util.Calendar; public class Main { /** * Using the expiry date, generate the application end date in the correct format. * * @param expiryMonth Month of expiry. * @param expiryYear Year of expiry. * @return The application end date in the correct format. */ private static String generateExpiryDate(String expiryMonth, String expiryYear) { // Just combine the year and month String applicationEndDate = expiryYear + expiryMonth; // Now need to work out the last day of the month // NB: Calendar's months range from 0-11 rather than 1-12 Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, Integer.parseInt(expiryYear)); calendar.set(Calendar.MONTH, Integer.parseInt(expiryMonth) - 1); applicationEndDate += calendar.getActualMaximum(Calendar.DATE); return applicationEndDate; } }