KeiroKamioka

FallJava_Assignment1-3[ErrorOnLine5]

Sep 30th, 2020
895
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Week1;
  2.  
  3. public class ProgrammingAssignment1 {
  4.     public static void main(String[] args) {
  5.         MonthDays getDay = new MonthDays();
  6.         getDay.getNumberOfDays(1, 1010);
  7.  
  8.     }
  9.  
  10.     class MonthDays {
  11.             int Month;
  12.             int Year;
  13.  
  14.         public MonthDays(){
  15.  
  16.         }
  17.         public int getMonth(){
  18.             return Month;
  19.         }
  20.         public int getYear(){
  21.             return Year;
  22.         }
  23.         public void setMonth(int theMonth){
  24.             Month = theMonth;
  25.         }
  26.         public void setYear(int theYear){
  27.             Year = theYear;
  28.         }
  29.  
  30.         public MonthDays(int theMonth, int theYear){
  31.             Month = theMonth;
  32.             Year = theYear;
  33.         }
  34.         public int getNumberOfDays(int theMonth, int theYear){
  35.             //Requirement 1 If the month argument is less than 1, or greater than 12 getNumberOfDays should throw a IllegalArgumentException exception.
  36.             if (theMonth <= 0){
  37.                 throw new IllegalArgumentException("the Month cannot be smaller than one");
  38.             }
  39.             if (theMonth >=13){
  40.                 throw new IllegalArgumentException("the Month cannot be larger than thirteen");
  41.             }
  42.             if (theYear <= 0){
  43.                 throw new IllegalArgumentException("the Year cannot be smaller than one");
  44.             }
  45.             //For months with 31 days
  46.             if (theMonth == 1 || theMonth == 3 || theMonth == 5 || theMonth == 7 || theMonth == 8 || theMonth == 10 || theMonth == 12){
  47.                 return 31;
  48.             }
  49.             //For months with 30 days
  50.             else if (theMonth == 4 || theMonth == 6 || theMonth == 9 || theMonth == 11){
  51.             //For the Feburary, detemine which is leap year or not
  52.                 return 30;
  53.             }
  54.             else if ((theYear % 100) == 0 && ((theYear % 400 ) == 0))
  55.             {
  56.                 //This is leap year
  57.                 return 29;
  58.             }
  59.             else if ((theYear % 100) != 0 && (theYear % 4) == 0){
  60.                 //This is also leap year
  61.                 return 29;
  62.             }
  63.             else {
  64.                 //It is not leap year
  65.                 return 28;
  66.             }
  67.         }
  68. }
  69.  
  70. class DaysSoFar {
  71.     int Month;
  72.     int Day;
  73.     int Year;
  74.  
  75.     public DaysSoFar(int theMonth, int theDay, int theYear){
  76.         Month = theMonth;
  77.         Day = theDay;
  78.         Year = theYear;
  79.  
  80.     }
  81.  
  82.     public int numberOfDaysSinceNewYear(int theMonth, int theDay, int theYear){
  83.         return -1;
  84.     }
  85.  
  86. }
  87.  
  88. }
  89.  
RAW Paste Data