Days
Given the poem:
Thirty days hath September
April, June, and November
All the rest have thirty-one
with February's 28 to make it fun.
Leap Year happening one in four, Gives February one day more.
Write a program that does the following:
1. Prompts the user for a month string (January, February, ...). Validate the input month string against an array of month's, and prompt the user again if the String entered is not a valid month. Note: You may want to use an Enum.
2. Prompts the user for a year (e.g. 2016).
3. For months with 31 days, output the phrase "all the rest have thirty-one". For September, the phrase "Thirty days hath September". For April, June, and November the phrase "April, June, and November". For February, if the year is not a leap year, output the phrase "with February's 28 to make it fun.". If the use did supply a leap year (and the user supplied February as the month), output the phrase "Leap Year happening one in four, Gives February one day more."
4.Note. Since this chapter covers Arrays and ArrayList objects, I expect your solution to utilize these facilities. The specifics of this is up to you (after all, this is your program :) ), so I am making specific requirements regarding this, other than you show learnings from chapter 7.
Please make sure you comment your code thoroughly. You are expected to use javadoc comments at the top of your code and above every method other than main. Refer to examples in the text or research javadoc on line if you have questions.
The code should be nicely formatted and should use proper variables.
Use switch statement not an else if statement.



OUTPUT


CODE
import java.io.*;
import java.lang.*;
import java.util.*;
class YearPoem {
/*
* if you don't want to use enum then the following lines(10-21) of code can be
* ignored. these lines are only if you want to use enum
*/
public static enum monthEnum {
January, February, March, April, May, June, July, August, September, October, November, December
}
public static boolean contains(String test) {
for (monthEnum type : monthEnum.values()) {
if (type.name().equals(test)) {
return true;
}
}
return false;
}
public static boolean checkLeapYear(int year) {
boolean isLeap = false;
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0)
isLeap = true;
else
isLeap = false;
} else
isLeap = true;
} else {
isLeap = false;
}
return isLeap;
}
public static void main(String[] args) throws Exception {
System.out.println("Enter Month");
Scanner sc = new Scanner(System.in);
/*
* if you eant to use array and list objects then use the following lines(46-53)
* of code
*/
String[] monthArray = { "January", "February", "March", "April", "May", "June", "July", "August", "September",
"October", "November", "December" };
String month = sc.next();
List monthList = Arrays.asList(monthArray);
while (monthList.contains(month) == false) {
System.out.println("Enter Month Again");
month = sc.next();
}
/*
* if you want to use enum then use this part of the code lines(60-64) and the
* lines (10-21) where the enum is created and a function to check month
* validity is written.This uses the method contains on the enum monthEnum to
* check if month is contained in the enum
*/
// while (contains(month) == false) {
// System.out.println("Enter Month Again");
// month = sc.next();
// }
System.out.println("Enter Year");
int year = sc.nextInt();
sc.close();
switch (month) { // switvh case used
case "January":
System.out.println("All the rest have thirty-one");
break;
case "February":
if (checkLeapYear(year)) {
System.out.println("Leap Year happening one in four, Gives February one day more.");
} else {
System.out.println("With February's 28 to make it fun.");
}
break;
case "March":
System.out.println("All the rest have thirty-one");
break;
case "April":
System.out.println("April, June, and November");
break;
case "May":
System.out.println("All the rest have thirty-one");
break;
case "June":
System.out.println("April, June, and November");
break;
case "July":
System.out.println("All the rest have thirty-one");
break;
case "August":
System.out.println("All the rest have thirty-one");
break;
case "September":
System.out.println("Thirty days hath September");
break;
case "October":
System.out.println("All the rest have thirty-one");
break;
case "November":
System.out.println("April, June, and November");
break;
case "December":
System.out.println("All the rest have thirty-one");
break;
}
}
}
Days Given the poem: Thirty days hath September April, June, and November All the rest have...
Given the poem: Thirty days hath September April, June, and November All the rest have thirty-one with February's 28 to make it fun. Leap Year happening one in four, Gives February one day more. How would I write this program using an Enum instead of an array? 1. Prompts the user for a month string (January, February, ...). Validate the input month string against an array of month's, and prompt the user again if the String entered is not a...
Javafx Given the poem: Thirty days hath September April, June, and November All the rest have thirty-one with February's 28 to make it fun. Leap Year happening one in four, Gives February one day more. Write a program that does the following: 1. Prompts the user for a month string (January, February, ...). Validate the input month string against an array of month's, and prompt the user again if the String entered is not a valid month. Note: You may...
Python Error: Writing a program to complete the following: Prompt the user for the name of an input file. Open that file for input. (reading) Read the file using a "for line in a file" loop For each line, o print the line and compute and print the average word length for that line. Close the input file Sample output: MY CODE IS WRONG AND NEED HELP CORRECTING IT!!! ------------------------------------------------------------------------------------------------------------------------ DESIRED OUTPUT: Enter input file name: Seasons.txt Thirty days hath September...
# JAVA In the following program, declare an integer array daysInMonth that stores the number of days in January, February, March, April, and so on. Fill it with the appropriate values (31, 28, 31, 30, ...).The program reads a month and year from the user.When the year is a leap year, change the entry for February to 29.Print out how many days the given month has.CODE:import java.util.Scanner;public class NumberOfDays{ public static void main(String[] args) { // Declare and initialize daysOfMonth ....
Cash Discount Review, Tu 41400 Chapter 8 and Distribution Finance Handy Rule: "30 days hath September. April June and November all the others have 31 expect February which has 28 and sometimes 29" (author unknown) 1. Calculate the cash discount offered and the amount paid as stated in the problems below: Item Invoice Amount Invoice Date Discount terms Date Pald Amount Pald a $1,790 1/10, n/30 3/1 3/10 $1,772.10 b. $7,194 2/10, n/30 3/28 4/17 $7,050 2. A distributor is...
JAVA CODE Beginner. please use if, else if or switch statements, but don't use arrays, please Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12...
Write a script in matlab that prompts the user to input the day, month, and year; determine the day of the year (the number of days including the current day). Be sure to take leap year into account. Use a for loop Test your code on the following dates: February 28, 2015 April 9, 1976 October 12, 1887 Create a script that performs the same function as repmat. The only built-in commands you may use are input, size, and disp.
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...
Occupancy-Days 3,400 280 Nm 0 0 Month January February March April May June July August September October November December Electrical Costs $ 10,234 $10,052 $11,605 $ 6,825 $ 2,380 $ 6,860 $ 11,060 $11,100 $ 7,602 $ 3,605 $ 4,634 $ 8,974 4,040 4,080 2,240 1,030 1,460 2,700 Required: 1. Using the high-low method, estimate the fixed cost of electricity per month and the variable cost of electricity per occupancy-day. (Do not round your intermediate calculations. Round your Variable cost...
PYTHON Build a regular expressions based on informal specifications to match specified patterns. Use a compiled regular expression in a Python program where appropriate. Use Python's text processing str methods to generate a string format converter. create a date format converter. Your program will convert a date in the format “mm/dd/yyyy” to the format “month day, year”. Specify the required input format: mm/dd/yyyy Use a regular expression to validate the user input date format. If the format is incorrect raise...