Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would I type part 2 so it has the same output as part 1? part1.) private sta

ID: 3785747 • Letter: H

Question

How would I type part 2 so it has the same output as part 1?

part1.)

private static int calDayInYear(int month, int day) {
int DayOfMonth [] = {31,28,31,30,31,30,31,31,30,31,30,31};
int calDay = 0;
public static void

for(int i=0; i < month-1; i++){
calDay = calDay + month;
}
return calDay+day;
}

Part 2.)

public static int calDayInYear(int month, int days){
if (month == 2){
return 28; //28 days
}else if (month == 4 || month == 6 || month == 9 || month == 11){
return 30; //30 days
}else{
return 31; //31 days
}
}

Explanation / Answer


public class TimeTest {
  
  
   /*private static int calDayInYear(int month, int day) {
       int DayOfMonth [] = {31,28,31,30,31,30,31,31,30,31,30,31};
       int calDay = 0;
  
       for(int i=0; i < month-1; i++){
       calDay = calDay + month;
       }
       return calDay+day;
       }*/
  
   public static int calDayInYear(int month, int days){
if (month == 2){
return 28+days; //28 days
}else if (month == 4 || month == 6 || month == 9 || month == 11){
return 30+days; //30 days
}else{
return 31+days; //31 days
}
   }

public static void main(String[] args) {
   int day=calDayInYear(6, 2);
   System.out.println(day);
}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote