Overview
For this assignment, each student will write a program that will calculate an end date given a starting date and number of days.
Prerequisites
- Follow the first set of instructions for installing Java found here. Do not do any of the instructions for JavaFX or Scene Builder.
- Be sure to download and run the x64 MSI Installer (the first link)
- Download and install IntelliJ IDEA. The Community Edition is all you'll need for this course, but you can download the Ultimate Edition and create a free student account, if you'd like.
- You will create a new project in IntelliJ called Lab3. Within the src/ folder in project you will create a new package named after your MSOE username. You will create a new Java program in this package.
- Except for the GitHub assignments after week 6, you will need to make a new project and repeat the prior steps on making a package with your MSOE username for all assignments.
Details
Most programming languages possess libraries for working with and manipulating times and dates. These libraries are essential because many real-world applications require tracking and representing the passage of time. However, representing and manipulating date and year information can be difficult because months have different numbers of days and there are leap years.
In this Lab, you must write a program called DateAdder.java, that asks the user for a start date in the form mm/dd/yyyy and a number from 0 to 100 inclusive to add. You must then print out the resulting date by adding the days entered. For example, if the user enters 12/15/2023 and 77, the end date would be March 1, 2024, which would be printed out as 03/01/2024. You must print out this end date in the form mm/dd/yyyy. See the sample output below.
You are not allowed to use any built-in Java libraries that deal with dates or times. You are also not allowed to use loops or arrays. You can assume the user enters a valid date and int for the days.
Enter a start date in the form mm/dd/yyyy 11/15/2025 Enter the number of days, which must be less than or equal to 100, to advance 47 47 day(s) after 11/15/2025 is 01/01/2026.
Just for fun
The following is not required, but can be added to your program once you are done if you are looking for an additional challenge or practice.
- When the user enters the number of days, check that the value is not less than 0 or greater than 100. When they user enters the date, check if it's valid such that the number of days does not exceed the maximum number of days for that month.
- Increase the max number of days to 500.
- Instead of asking for the number of days, ask the user for the end date and calculate the number of days between. Make is so that the program can switch between asking for a number of days or end date.
- Make the number of days to advance unlimited. Note, this will require loops and should be done not at a part of your main submission.
Acknowledgement
This laboratory assignment was developed by Dr. Roby Velez.