
Patrick B. answered 10/06/20
Math and computer tutor/teacher
import java.io.*;
class LabProgram
{
private Console console;
LabProgram()
{
console = System.console();
}
public int PromptForInt( String msgStr)
{
System.out.println("******************************");
System.out.print(msgStr);
String inbuff = console.readLine();
return(Integer.parseInt(inbuff));
}
public boolean isLeapYear(int userYear)
{
boolean boolReturn=true;
if ((userYear%4)==0) // MUST be divisible by 4
{
if ((userYear%100)==0) //IF it is a century, it must be divisible by 400
{
boolReturn = ((userYear%400)==0);
}
}
else //not divisible by 4
{
boolReturn=false;
}
return(boolReturn);
}
public void Go()
{
int year = PromptForInt("Please input the year :>");
if (isLeapYear(year))
{
System.out.println( year + " is a leap year" );
}
else
{
System.out.println( year + " is not a leap year");
}
}
public static void main(String args[])
{
LabProgram x = new LabProgram();
x.Go();
}
}