1. public static boolean isLeapYear (int year) Returns whether or not the given
ID: 3732226 • Letter: 1
Question
1. public static boolean isLeapYear (int year) Returns whether or not the given year is a leap year. 2. public static int dayofYear (int month, int day, int year) Return the day of the year. Return -1 if the date is not valid 3. public static int daysRemaining(int month, int day, int year) Return the number of days remaining in the year. Return -1 the date is not valid. 4. public static boolean isDatevalid(int month, nt day, int year) Return whether or not the date given is valid.(Valid years are 1800 to 3000, inclusive.) 5. public static short daysInNonth(int month, int year) Given a month number, return the number of days in that month for that year. Return 0 if the month is not valid. 6. public static void dateReport (int month, int day, int year) Print out a date report for the given date as shown in the sample runs. 7. public static short monthNameToNumber (String month) Given a String of the full month "January" or the first three letters "Jan" . return the month's position in the year. For example, " jUL" would return 7 ·Invalid months should return -1 . (case insensitive) 8. public static String monthNumberToName (int month) Given a month of the year, return the full name of the month as a string or INVALID otherwise. 9. public static int daysBetween(int ml, int d, int yl. int m2, int d2, int y2) Return the number of days between two dates in the same year. If either of the dates are invalid or the years are not the same, return-1 10. public static long millisecLeftInYear (int month, int day, int year) Return the number of milliseconds left in a year. You may assume 24-hour days and work in whole-day increments. 11 public static void printMenu) Print out the choice menu as shown in the sample runs. 12. public static int getPosNum(int max) Prompt the user to "Enter a positive number up to [max]· " until a valid number is read in. See the sample runs for an example. If max is not a positive number, return 0Explanation / Answer
The code can be directly executed.
Answer#1
<html>
<head>
<script>
function leapYear(year)
{
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
}
</script>
</head>
<body>
Leap year checking <br>
<script>
var res = leapYear(2001);
document.write(res);
</script>
</body>
</html>
-----------------
Answer#2
<html>
<head>
<script>
function dayOfYear(month, day, year)
{
if (month<12 && day<31)
{
var now = new Date(year, month, day);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
return(day);
}
else
return(-1);
}
</script>
</head>
<body>
Day of the year <br>
<script>
doy = dayOfYear(2, 18, 2018);
document.write(doy);
</script>
</body>
</html>
-----------------
Answer#3
<html>
<head>
<script>
function dayOfYear(month, day, year)
{
if (month<12 && day<31)
{
var now = new Date(year, month, day);
var start = new Date(now.getFullYear(), 0, 0);
var diff = now - start;
var * 60 * 60 * 24;
var day = Math.floor(diff / oneDay);
var dr = 365 - day;
return(dr);
}
else
return(-1);
}
</script>
</head>
<body>
Days remaining in the year <br>
<script>
rem = dayOfYear(2, 18, 2018);
document.write(rem);
</script>
</body>
</html>
-----------------
Answer#4
<html>
<head>
<script>
function isDateValid (month, day, year){
if(day == 0 ){
return false;
}
switch(month){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
if(day > 31)
return false;
return true;
case 2:
if (year % 4 == 0)
if(day > 29){
return false;
}
else{
return true;
}
if(day > 28){
return false;
}
return true;
case 4: case 6: case 9: case 11:
if(day > 30){
return false;
}
return true;
default:
return false;
}
}
</script>
</head>
<body>
Is date valid: <br>
<script>
res = isDateValid(20, 18, 2018);
document.write(res);
</script>
</body>
</html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.