Commit 79e03410 authored by a-j.towse's avatar a-j.towse

MonthBetween

parent 1d45eca2
import java.time.Year;
//Excercises for week 2 //Excercises for week 2
public class App { public class App {
...@@ -44,44 +46,22 @@ public class App { ...@@ -44,44 +46,22 @@ public class App {
return(false); return(false);
} }
} }
public static void main(String[] args) throws Exception { /*public static String monthCount(int monthNum){
countDays(); switch(monthNum){
circumference(10); case 1 : return("January");
inigoSpeech(6); case 2 : return("February");
isItALeapYear(2016); case 3 : return("March");
case 4 : return("April");
case 5 : return("May");
case 6 : return("June");
int month = 0; case 7 : return("July");
for(month = 1; month < 14; month++){ case 8 : return("August");
switch(month){ case 9 : return("September");
case 1 : System.out.println("January"); case 10 : return("October");
break; case 11 : return("Novemeber");
case 2 : System.out.println("February"); case 12 : return("December");
break; default : return("Not a valid month");
case 3 : System.out.println("March");
break;
case 4 : System.out.println("April");
break;
case 5 : System.out.println("May");
break;
case 6 : System.out.println("June");
break;
case 7 : System.out.println("July");
break;
case 8 : System.out.println("August");
break;
case 9 : System.out.println("September");
break;
case 10 : System.out.println("October");
break;
case 11 : System.out.println("Novemeber");
break;
case 12 : System.out.println("December");
break;
default : System.out.println("Not a valid month");
break;
} }
} }
while(month < 14){ while(month < 14){
...@@ -145,7 +125,59 @@ public class App { ...@@ -145,7 +125,59 @@ public class App {
break; break;
} }
}while(month < 14); }while(month < 14);
}*/
public static int daysInMonth(int monthNum, int currentYear){
if(isItALeapYear(currentYear) == true){
int febDays = 29;
}
else{
int febDays = 28;
}
switch(monthNum){
case 1 : return(31);
case 2 : return(febDays);
case 3 : return(31);
case 4 : return(30);
case 5 : return(31);
case 6 : return(30);
case 7 : return(31);
case 8 : return(31);
case 9 : return(30);
case 10 : return(31);
case 11 : return(30);
case 12 : return(31);
default : return(1);
}
}
public static int daysMonthLeft(int startDay, int startMonth, int currentYear){
int daysLeft = (daysInMonth(startMonth,currentYear)-startDay);
return daysLeft;
}
public static int daysBetween(int startDay, int startMonth, int startYear, int endDay, int endMonth, int endYear){
System.out.println(monthCount(12));
int days = 0;
days += daysMonthLeft(startDay, startMonth, currentYear)
return days;
}
public static void main(String[] args) throws Exception {
/*countDays();
circumference(10);
inigoSpeech(6);
isItALeapYear(2016);
*/
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment