import java.util.Scanner;
public class Leap {
Scanner input = new Scanner(System.in);
public static int year;
//getYear method
public int getYear() {
int year;
System.out.printf("Enter a year after 1752 and before 10000> ");
year=input.nextInt();
while(year<=1752 || year>=10000) {
System.out.printf("%d is not a valid year, try again!\n",year);
System.out.print("Enter a year after 1752 and before 10000> ");
year=input.nextInt();
}
return year;
}
//isLeapYear method
public static boolean isLeapYear() {
if(year % 4==0 && year % 100!=0 || year % 400==0) {
return true;
}else{
return false;
}
}
//getLeapDay method
public String getLeapDay() {
int r1 = year % 400;
int d1 = r1 / 100;
int offset = d1 * (-2);
int r2 = year % 100;
int offset2= r2/12;
int offset3=r2%12;
int offset4=offset3/4;
int total=offset+offset2+offset3+offset4;
int day;
if(total<0){
day=total+7;
}else{
day=total % 7;
}
switch(day){
case 0:
day=0;
break;
case 1:
day=1;
break;
case 2:
day=2;
break;
case 3:
day=3;
break;
case 4:
day=4;
break;
case 5:
day=5;
break;
case 6:
day=6;
break;
}
}
//main method
public static void main(String args[]) {
System.out.println("*** Leap Year Calculator ***");
Leap year = new Leap();
year.getYear();
Leap isLeap = new Leap();
isLeap.isLeapYear();
Leap getDay = new Leap();
getDay.getLeapDay();
/*
if (isLeapYear(year)) {
System.out.printf ("%d is leap and the day is ",year);
} else {
System.out.println ("%dis not leap",year);
}
*/
}
}
As you can see I'm trying make instances in my main and trying to call my other 3 methods. The compiler error I received: Leap.java:91: missing return statement. Also, does anyone have any tips how to get my boolean method to display in text whether or not the entered value is leap or not? Any help is highly appreciated
public class Leap {
Scanner input = new Scanner(System.in);
public static int year;
//getYear method
public int getYear() {
int year;
System.out.printf("Enter a year after 1752 and before 10000> ");
year=input.nextInt();
while(year<=1752 || year>=10000) {
System.out.printf("%d is not a valid year, try again!\n",year);
System.out.print("Enter a year after 1752 and before 10000> ");
year=input.nextInt();
}
return year;
}
//isLeapYear method
public static boolean isLeapYear() {
if(year % 4==0 && year % 100!=0 || year % 400==0) {
return true;
}else{
return false;
}
}
//getLeapDay method
public String getLeapDay() {
int r1 = year % 400;
int d1 = r1 / 100;
int offset = d1 * (-2);
int r2 = year % 100;
int offset2= r2/12;
int offset3=r2%12;
int offset4=offset3/4;
int total=offset+offset2+offset3+offset4;
int day;
if(total<0){
day=total+7;
}else{
day=total % 7;
}
switch(day){
case 0:
day=0;
break;
case 1:
day=1;
break;
case 2:
day=2;
break;
case 3:
day=3;
break;
case 4:
day=4;
break;
case 5:
day=5;
break;
case 6:
day=6;
break;
}
}
//main method
public static void main(String args[]) {
System.out.println("*** Leap Year Calculator ***");
Leap year = new Leap();
year.getYear();
Leap isLeap = new Leap();
isLeap.isLeapYear();
Leap getDay = new Leap();
getDay.getLeapDay();
/*
if (isLeapYear(year)) {
System.out.printf ("%d is leap and the day is ",year);
} else {
System.out.println ("%dis not leap",year);
}
*/
}
}
As you can see I'm trying make instances in my main and trying to call my other 3 methods. The compiler error I received: Leap.java:91: missing return statement. Also, does anyone have any tips how to get my boolean method to display in text whether or not the entered value is leap or not? Any help is highly appreciated