Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2-Write a program. MonthsToNumbers.java Write a program that: .The progr

ID: 3750151 • Letter: P

Question

Problem 2-Write a program. MonthsToNumbers.java Write a program that: .The program asks the user to specify the name of a month. It should not make a difference whether any letter in the name appears in lower case or upper case all such variations should be accepted by the program. If the user entered correctly the name of a month, the program prints out the month name, and the order of that month in the year (e.g., January is the first month, July is the seventh month, and so on). Note that when the program prints out the month name, the first letter of the month name should be capitalized, and all other letters should be in lower case. If the user enters a name that is not recognized, the program prints out "Unknown month:" and the name entered by the user. Note that the name . entered by the user should be printed exactly as entered by the user (with no conversions of any letters to upper or lower case). Example Program Run 1 Please enter the name of a month: juNE June is the sixth month.

Explanation / Answer


Given below is the code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you

import java.util.Scanner;
public class MonthsToNumbers {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String month;
System.out.print("Please enter the name of a month: ");
month = keyboard.next();
if(month.equalsIgnoreCase("January"))
System.out.println("January is the first month.");
else if(month.equalsIgnoreCase("February"))
System.out.println("February is the second month.");
else if(month.equalsIgnoreCase("March"))
System.out.println("March is the third month.");
else if(month.equalsIgnoreCase("April"))
System.out.println("April is the fourth month.");
else if(month.equalsIgnoreCase("May"))
System.out.println("May is the fifth month.");
else if(month.equalsIgnoreCase("June"))
System.out.println("June is the sixth month.");
else if(month.equalsIgnoreCase("July"))
System.out.println("July is the seventh month.");
else if(month.equalsIgnoreCase("August"))
System.out.println("August is the eighth month.");
else if(month.equalsIgnoreCase("September"))
System.out.println("September is the ninth month.");
else if(month.equalsIgnoreCase("October"))
System.out.println("October is the tenth month.");
else if(month.equalsIgnoreCase("November"))
System.out.println("November is the eleventh month.");
else if(month.equalsIgnoreCase("December"))
System.out.println("December is the twelfth month.");
else
System.out.println("Unknown month: " + month);
}
}

output
------
Please enter the name of a month: juNE
June is the sixth month.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote