Question
JAVA Please put detailed comments as well explaining your program. I'm in a beginning programming class, and so please use more basic techniques such as
JAVA
Please put detailed comments as well explaining your program.
I'm in a beginning programming class, and so please use more basic techniques such as if else statements, switch operators, and for loops if needed.
http://imgur.com/a/xx9Yc
Pseudocode for the main method:
Print the headings
Print the directions
Prompt for the month
If the month is an integer (Hint: Use the Scanner class hasNextInt method.)
Input the integer for the month
Get the string for the month (Use your method)
Otherwise
Input the string for the month
Get the integer for the month (Use your method)
Prompt for the day
Input the day
Prompt for the year
Input the year
Get the holiday
Print the output
THE PROBLEM:
You must use switch statements for some part of the homework.
Write a program that inputs a month, day, and year from the user and outputs the corresponding date in the following two standard date formats:
6/12/2005 June 12, 2005
Also your program must print the name of any holiday associated with the date.
For example:
3/17/2010 March 17, 2010 St. Patricks Day
Your program should ask the user how many times the user wants to run the code and then you need to use a for loop to repeat the run that many times.
REQUIREMENTS:
You must use good programming style.
The user can enter the month either as a numeric value or a String. i.e. the user could enter a 5 or May.
You may assume the data that the user enters is valid data.
Your program must print a report similar to that shown in the sample output on the last page of this handout.
You must solve this problem by implementing and using the following methods:
printDirections
void method that prints a message to the user that explains what the program will do and how the month data can be entered. (See the sample output above.)
getMonthString
method that has 1 parameter, the month as an integer (1..12).
This method returns the corresponding name of the month as a String.
getMonthNumber
method that has 1 parameter, the name of the month in a String.
This method returns the corresponding integer value for that month name.
HINT: Before you read the data for the month, use the Scanner class hasNextInt method to determine what kind of data the user entered for the month. Using hasNextInt you can determine if the user is entering an integer for the month or not.
getHoliday
This method has 2 int type parameters for month and day.
The method returns a String that is the name of a holiday that is associated with the date represented by the parameters. If there is no holiday associated with that date, then the method returns an empty String ().
Use nested switch statements to implement this method. Use one switch statement for the months. Inside the case for each month, use a switch statement that has a case for each day in that month that is a holiday. Inside each of those day cases, set the holiday string to the name of the holiday.
NOTE: You can also include holidays for your birthday, anniversary, or whatever
isEaster
This method has 3 int type parameters for month, day and year.
This method returns true if the date represented by the 3 parameters is Easter, otherwise it returns false.
To implement this method: use the following formula to figure out the month and the day of easter for the given year.
goldenNumber = (year % 19) + 1;
a = (24 + 19*(goldenNumber - 1)) % 30; b = a - a/28;
c = (year + year/4 + b - 13) % 7; d = b - c;
easterMonth = 3 + (d + 40)/44;
easterDay = d + 28 - 31*(easterMonth/4);
To use this method, you will have to add a third parameter to the getHoliday method for the year, and then inside the getHoliday method, after the switch statements, call this method.
NOTE: If the holiday string is already longer than 0, this day is already associated with another holiday,
(For example, maybe Grandmas Birthday, then getHoliday should return Easter and Grandmas Birthday.
To test the isEaster method, make April 4 Grandmas Birthday and test this method using 4/4/2010. Also test it for Easter in a year where Easter is not on April 4.
Here is a list of holidays that your need needs to generate the appropriate output:
1/1 "New Year's Day";
1/18 "Martin Luther King Jr. Day";
2/2 "Ground Hog Day";
2/12 "Abraham Lincoln's Birthday";
2/14 "St. Valeninte's Day";
2/22 "George Washington's Birthday";
3/17 "St. Patrick's Day"; 4/1 "April Fool's Day";
4/4 "Grandma's Birthday";
4/22 "Earth Day";
4/30 "Arbor Day";
5/1 "May Day";
5/5 "Cinco de Mayo";
7/4 "Independence Day";
8/1 "International Friendship Day";
10/1 "Columbus Day";
10/31 "Halloween";
11/11 "Vereran's Day";
12/25 "Christmas";
12/31 "New Year's Eve";
?? "Easter";
Sample outputs
CSC 15 Chapter 4 [Your Name] This program will ask you for a month, day, and year and will print the corresponding date in two standard date formats. You may enter the month as: * a numeric value (1..12) or as * an unabbreviated month name (January or February etc....) How many times do you want to run the program: 3
Enter the month: 10 Enter the day: 31 Enter the year: 2010
The Date is: 10/31/2010 October 31, 2010 Halloween Enter the month: 1 Enter the day: 1 Enter the year: 2014
The Date is: 1/1/2014 January 1, 2014 New Year's Day Enter the month: 4 Enter the day: 4 Enter the year: 2010
The Date is: 4/4/2010 April 4, 2010 Easter and Grandma's Birthday |
Pseudocode for the main method:
Print the headings
Print the directions
Prompt for the month
If the month is an integer (Hint: Use the Scanner class hasNextInt method.)
Input the integer for the month
Get the string for the month (Use your method)
Otherwise
Input the string for the month
Get the integer for the month (Use your method)
Prompt for the day
Input the day
Prompt for the year
Input the year
Get the holiday
Print the output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started