import java.util.*;
public class Main
{
static boolean leap(int year)//function to find leap year
{
boolean leap1=false;//intialize to false first
if(year % 4 == 0)
{
if( year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year % 400 == 0)
leap1 = true;
else//in else case it is false
leap1 = false;
}
else
leap1=true;
}
else
leap1=false;
return leap1;//return the status of leap year in boolean
format
}
public static void main(String[] args) {
int
dayNumber,monthNumber,date,year;
int
monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31};//no.of days of
each months
String[] days=new String[]
{"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};//it
is initialized for finding from 1 to 7 values
//we can directly access their
names using array index of day or month to find their name
String[] month=new String[]
{"January","February","March","April","May","June","July","August","September","November","December"};//months
for numbers 1 to 12
Scanner s=new
Scanner(System.in);
System.out.println("ener 4 integers
representing dayNumber monthNumber date year");
dayNumber=s.nextInt();//read the
four values
monthNumber=s.nextInt();
date=s.nextInt();
year=s.nextInt();
if(dayNumber>=1&&dayNumber<=7)//it first checks for
dayNumber 1 to 7 if true goes in else prints invalid day
{
if(monthNumber>=1&&monthNumber<=12)//chjecks for
valid month
{
if(monthNumber!=2&&monthDays[monthNumber-1]>=date)//checks
for other than february and if date matches with array
monthDays
{
System.out.println("dayNumber
monthNumber date year is "+days[dayNumber-1]+"
"+month[monthNumber-1]+" "+date+" "+year);//if true print
them
}
else if(monthNumber==2)//if it is
February
{
if(leap(year))//checks for leap
year if true
{
if(date<=29)//checks for
date<=29
{
System.out.println("dayNumber
monthNumber date year is "+days[dayNumber-1]+"
"+month[monthNumber-1]+" "+date+" "+year);
}
else//if it greater then
Invalid
System.out.println("Invalid
date:"+date+"Please enter from 1 to 29 leap year");
}
else
{
if(date<=28)//checks until 28
only
{
System.out.println("dayNumber
monthNumber date year is "+days[dayNumber-1]+"
"+month[monthNumber-1]+" "+date+" "+year);
}
else
{
System.out.println("Invalid
date:"+date+"Please enter from 1 to 28 for february");
}
}
}
else//else it is Invalid
{
System.out.println("Invalid
date:"+date+"Please enter from 1 to 31");
}
}
else//month Invalid if else
block
{
System.out.println("Invalid
month:"+monthNumber+"please enter from 1 to 12");
}
}
else//day Invalid else block
{
System.out.println("Invalid
day:"+dayNumber+"please enter from 1 to 7");
}
}
}
leap year output
correct details
invalid day
invalid month
invalid date
CK CUNYOMP 167 al 2019/chapter/ X M X C Does Musical WePACCOU XG Persol chapter/4/section/23 Inbox...
Lab/HW 3 Write a program that reads in the following data, all entered on one line with at least one space separating them: a) an integer representing a month b) an integer representing the day of the month c) an integer representing a year 1. Check that the month is between 1 and 12. If it’s not print an error message. 2. Day cannot be 0 or less nor can it be more than 31 for all months. Print...
C Programming Quesition (Structs in C): Write a C program that prompts the user for a date (mm/dd/yyyy). The program should then take that date and use the formula on page 190 (see problem 2 in the textbook) to convert the date entered into a very large number representing a particular date. Here is the formula from Problem 2 in the textbook: A formula can be used to calculate the number of days between two dates. This is affected by...
C++ 1. Start with a UML diagram of the class definition for the following problem defining a utility class named Month. 2. Write a class named Month. The class should have an integer field named monthNumber that holds the number of the month (January is 1, February is 2, etc.). Also provide the following functions: • A default constructor that sets the monthNumber field to 1. • A constructor that accepts the number of month as an argument and sets...
c++ please :) First, ask the user to enter a year (4-digit) and what week day does this year starts with (String) For example, the year 2018 starts with the week day "Friday". In this case, the calendar should start from January 1 which is Friday, 2018 Your program should produce a formatted calendar for the specified year and there should be a blank line after each month. Moreover, the month and the year should be centered over each month....
Hi please help me with this zybooks question asap. Thanks 4.17 Chapter 4 Program: Sum of Numbers/C++ program Write a C ++ program that asks the user for a positive integer value by prompting "Enter a positive integer number: ", read in that number, then use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2,3, 4…50....
the coding language is just the basic c language and here is my first attempt at this problem my problem is that if the user inputs a number that is equal to a number that has been entered previously the code will never end until the user enters a number that is bigger than any other number previously entered any help will be helpful Write a program to read-in a sequence of integers from the keyboard using scanf(). Your program...
An ordinal date consists of a year and a day within it, both of which are integers. The year can be any year in the Gregorian calendar while the day within the year ranges from one, which represents January 1, through to 365 (or 366 if the year is a leap year) which represents December 31. Ordinal dates are convenient when computing differences between dates that are a specific number of days (rather than months). For example, ordinal dates can...
PYTHON I need some basic python homework help! Write a program that prompts the user to enter a date (day, month, and year). Your program will print out the day of the week for that date. You do not need to validate the input. That means you can assume: the year will be entered as a four-digit number in the range 1900 through 2100 inclusive. the month will be one of the strings "January", "February", . . ., "December". the...
Assuming that a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example, Day 2 would be January 2. Day 32 would be February 1. Day 365 would be December 31. The constructor for the class should take as parameter an integer representing the day of the year, and the class should have...