Browse Source

Done this took a long time.......

master
Raphael Roberts 6 years ago
parent
commit
628f4f4e2e
  1. 2
      .gitignore
  2. 28
      prog/IncDate.java

2
.gitignore

@ -1,2 +1,4 @@
/HW1.zip
/HW1.pdf
*.7z
*.class

28
prog/IncDate.java

@ -19,5 +19,33 @@ public class IncDate extends Date
public void addDays(int numDays)
{
// TODO: implement this method
int days_to_add = numDays;
int[] MONTHS = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
boolean is_leap = (m_year % 400 == 0) || ((m_year % 4 == 0) && !(m_year % 100 == 0));
for (int current_month = 0; current_month < m_month-1; current_month ++)
days_to_add += MONTHS[current_month];
if ((m_month > 2) && is_leap)
days_to_add += 1;
days_to_add += m_day-1;
m_month = 1;
m_day = 1;
while (days_to_add > 365) {
is_leap = (m_year % 400 == 0) || ((m_year % 4 == 0) && !(m_year % 100 == 0));
if (is_leap)
days_to_add -= 1;
days_to_add -= 365;
m_year += 1;
}
is_leap = (m_year % 400 == 0) || ((m_year % 4 == 0) && !(m_year % 100 == 0));
if (is_leap)
MONTHS[1] +=1;
while (days_to_add >= MONTHS[m_month-1]) {
days_to_add -= MONTHS[m_month-1];
m_month += 1;
}
m_day=days_to_add+1;
}
}
Loading…
Cancel
Save