Advertisement
KeiroKamioka

FallJava_Assignment1-2[ErrorOnLine5]

Sep 30th, 2020
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  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.         public int getNumberOfDays(int theMonth, int theYear){
  12.             //Requirement 1 If the month argument is less than 1, or greater than 12 getNumberOfDays should throw a IllegalArgumentException exception.
  13.             if (theMonth <= 0){
  14.                 throw new IllegalArgumentException("the Month cannot be smaller than one");
  15.             }
  16.             if (theMonth >=13){
  17.                 throw new IllegalArgumentException("the Month cannot be larger than thirteen");
  18.             }
  19.             if (theYear <= 0){
  20.                 throw new IllegalArgumentException("the Year cannot be smaller than one");
  21.             }
  22.             //For months with 31 days
  23.             if (theMonth == 1 || theMonth == 3 || theMonth == 5 || theMonth == 7 || theMonth == 8 || theMonth == 10 || theMonth == 12){
  24.                 return 31;
  25.             }
  26.             //For months with 30 days
  27.             else if (theMonth == 4 || theMonth == 6 || theMonth == 9 || theMonth == 11){
  28.             //For the Feburary, detemine which is leap year or not
  29.                 return 30;
  30.             }
  31.             else if ((theYear % 100) == 0 && ((theYear % 400 ) == 0))
  32.             {
  33.                 //This is leap year
  34.                 return 29;
  35.             }
  36.             else if ((theYear % 100) != 0 && (theYear % 4) == 0){
  37.                 //This is also leap year
  38.                 return 29;
  39.             }
  40.             else {
  41.                 //It is not leap year
  42.                 return 28;
  43.             }
  44.         }
  45. }
  46.  
  47. class DaysSoFar {
  48.  
  49. }
  50.  
  51. }
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement