Amazon Interview Question
Testing / Quality AssurancesTeam: QAE
Country: India
Interview Type: In-Person
Bounday Values should be
Year and month change
A. 27/12/2012 it should return 31/12/2012
B. 28/12/2012 it should return 1/1/2013
Leap year check
1. 25/02/2012 it should return 29/02/2012
2. 26/02/2012 it should return 01/03/2012
3. 25/02/2013 it should return 01/03/2013
4. 24/02/2013 it should return 28/02/2013
No need to check 31st as we already tested it on scenario A,B
Check 30 days change also.
String input = "28/12/9999";
String[] splitArray = input.split("/");
Integer date = Integer.parseInt(splitArray[0]);
Integer month = Integer.parseInt(splitArray[1]);
Integer year = Integer.parseInt(splitArray[2]);
boolean leapYear = year%4 == 0 ? true : false;
boolean is31Days = false;
if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
is31Days = true;
boolean isfeb = month == 2? true : false;
date = date+4;
if((is31Days && date > 31))
{
month +=1; date = date - 31;
}
else if(!is31Days && date > 30)
{
month +=1; date = date - 31;
}
else if ((isfeb && leapYear && date > 29 ) )
{
month +=1; date = date - 29;
}
else if (isfeb && !leapYear && date > 28 ){
month +=1; date = date - 28 ;
}
if(month == 13){
month = 1;
year +=1;
}
System.out.print((date.toString().length()==1?"0":"") + date.toString() + "/" + (month.toString().length() == 1 ? "0" : "")+month.toString()+"/"+year.toString());
1. Check leap year like: 25-02-2010, shld output 29-02-2010
- James Anderson April 22, 20142. Normal testcases like what you mentioned
3. Month change
-> 31 days months
-> 30 days months
-> 28 days months
4. Year change like 28-12-2013 - 01-01-2013
Other: The format should always be dd/mm/yyyy