Question: The following code is a slightly modified version of actual code that was in the Microsoft Zune music player in 2008. The code attempts to

The following code is a slightly modified version of actual code that was in the Microsoft Zune music player in 2008. The code attempts to calculate today’s date by determining how many years and days have passed since 1980. Assume the existence of methods for getting the total number of days since 1980 and for determining whether a given year is a leap year:

int days getTotalDaysSince1980 () ; year 1980; while (days > 365) { // subtract out years if (isLeapYear (year)) { if (days > 366) { days 366; year += 1; } } else { days 365; year += l; } }

Thousands of Zune players locked up on January 1, 2009, the first day after the end of a leap year since the Zune was released. (Microsoft quickly released a patch to fix the problem.) What is the problem with the preceding code, and in what cases will it exhibit incorrect behavior? How can it be fixed?

int days getTotalDaysSince1980 () ; year 1980; while (days > 365) { // subtract out years if (isLeapYear (year)) { if (days > 366) { days 366; year += 1; } } else { days 365; year += l; } }

Step by Step Solution

3.42 Rating (171 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The Zune code will get stuck in an infinite loop when the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!