3. Using no date-specific Java libraries, write a program that
computes
the number of days between any two dates (inclusive). You must
take
into account leap years. The rule for computing a leap year is
as
follows: If the year is divisible by 4 it is a Leap Year ...
Unless the year is divisible by 100, then it is _not_ a Leap
Year
... Unless the year is divisible by 400, then it _is_ a Leap
Year.
During a Leap year, an extra day is added at the end of the
month
of Feb.
ex. 1000 is not a Leap Year
2000 is a Leap year
Your program must be run as follows:
PROMPT>> java DaysBetween 11/11/2002 11/12/2002
1 day
(program ends)
Error checking. Be sure to handle at least the following:
- if there is too few or too many input parameters
- if the date strings are not in the proper format
(simply echo usage statement);
- if date 1 is not earlier than date 2
I HOPE ITS HELPFULL TO YOU ...IF YOU HAVE ANY DOUBTS PLS COMMENTS BELOW...I WILL BE THERE TO HELP YOU...PLS RATE THUMBS UP...!!
ANSWER::-
as for given data....
Using Localdate Java libraries, write a program that
computes
the number of days between any two dates (inclusive).
You must take
into account leap years. The rule for computing a leap
year is as
follows: If the year is divisible by 4 it is a Leap
Year ...
Unless the year is divisible by 100, then it is _not_
a Leap Year
... Unless the year is divisible by 400, then it _is_
a Leap Year.
During a Leap year, an extra day is added at the end
of the month
of Feb.
CODE ::-
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
public class DaysBetween {
public static void main(String[] args) {
try {
if(args.length==2) {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("MM/dd/yyyy");
LocalDate startDate = LocalDate.parse(args[0],formatter);
LocalDate endtDate = LocalDate.parse(args[1],formatter);
Long range = ChronoUnit.DAYS.between(startDate, endtDate);
if(range<0) {
System.out.println("date 1 is not earlier than date
2");
}else {
System.out.println(range+" day");
}
}else {
System.out.println("Please check
the command line lengh");
}
}catch(Exception e){
System.out.println("Please give the
correct date format as MM/DD/YYYY");
}
}
}
Running program:
java DaysBetween 03/01/1000 02/29/1000
OUT PUT ::-
date 1 is not earlier than date 2
Run2:
java DaysBetween 11/11/2002 11/12/2002
1 day
THANK YOU...!!
3. Using no date-specific Java libraries, write a program that computes the number of days between...
JAVA programing Question 1 (Date Class): 5 Points Create a class Date with the day, month and year fields (attributes). Provide constructors that: A constructor that takes three input arguments to initialize the day, month and year fields. Note 1: Make sure that the initialization values for the day, month and year fields are valid where the day must be between 1 and 31 inclusive, the month between 1 and 12 inclusive and the year a positive number. Note 2:...
In Java You are to write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program: /** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of...
PLEASE WRITE CODE FOR C++ ! Time Validation, Leap Year and Money Growth PartA: Validate Day and Time Write a program that reads a values for hour and minute from the input test file timeData.txt . The data read for valid hour and valid minute entries. Assume you are working with a 24 hour time format. Your program should use functions called validateHour and validateMinutes. Below is a sample of the format to use for your output file timeValidation.txt : ...
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...
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...
Hi any help is appreciated! I am using C++. The Julian Day Number (JDN) is a sequential count of days since the beginning of the Julian Period. Day number zero corresponds to 1 January 4713 BCE. As a result of calendar reform in the 16th Century, we will only be computing day numbers since 15 October 1582 (which was the first day of the modern Gregorian calendar, having day number 2299161). 1 January 2001 was day number 2451911. To compute...
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...
Use Java please Creating a calendar for a given year A shell for this assignment has been provided so that you can fill in the methods Homework 4 grading rubric 1. Output examples a. One Normal Year, 10% b. One Leap Year, 10% 2. Style Meaningful variable names, 10% b. Meaningful method names, 10 % c. Comments, Total: 10% . Do not comment every line. 5% . Comment non-obvious code. 5% a d. Indentation, 10% e. Block comment with name...
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do. To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary. Write a Test Class for Your SpeedDating Class Your test class will have a main method that does the following: Create a SpeedDating object Since 1971, Columbus Day...