Machine Problem in Java
Write a program that will ask the user month based on numerical values 1,2,3,4,5,6,7,8,9,10,11 and 12 which represents January, February, March, April, May, June, July, August, September, October, November. December using Java programming language with Error Handling function.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com
If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.
Your support on my channel is highly appreciated.
Thank you very much.
Program Listing
Month_Selection.java
import java.util.InputMismatchException;
import java.util.Scanner;
/**
Machine Problem in Java
Write a program that will ask the user month based on numerical values
1,2,3,4,5,6,7,8,9,10,11 and 12 which represents January, February, March,
April, May, June, July, August, September, October, November
@author Jake Rodriguez Pomperada,MAED-IT, MIT
www.jakerpomperada.com / www.jakerpomperada.blogspot.com
jakerpomperada@gmail.com
Bacolod City, Negros Occidental Philippines
February 12, 2021 12:05 PM Friday
*/
public class Month_Selection {
static void end()
{
System.out.println();
System.out.println("\tEnd of Program");
System.exit(0);
}
static void display()
{
Scanner in = new Scanner(System.in);
int ch;
do {
ch = 0;
System.out.println();
System.out.println("\tMonth Selector in Java");
System.out.println();
System.out.print("\tEnter month's number: ");
int monthNumber = in.nextInt();
System.out.println();
if (monthNumber == 1)
System.out.println("\tJanuary");
else if (monthNumber == 2)
System.out.println("\tFebruary");
else if (monthNumber == 3)
System.out.println("\tMarch");
else if (monthNumber == 4)
System.out.println("\tApril");
else if (monthNumber == 5)
System.out.println("\tMay");
else if (monthNumber == 6)
System.out.println("\tJune");
else if (monthNumber == 7)
System.out.println("\tJuly");
else if (monthNumber == 8)
System.out.println("\tAugust");
else if (monthNumber == 9)
System.out.println("\tSeptember");
else if (monthNumber == 10)
System.out.println("\tOctober");
else if (monthNumber == 11)
System.out.println("\tNovember");
else if (monthNumber == 12)
System.out.println("\tDecember");
else
System.out.println("\tInvalid month. Try Again");
System.out.println();
try{
System.out.print("\tContinue (Type 1 - Yes or 2 - No) : ");
ch = in.nextInt();
} catch (InputMismatchException e) {
System.out.println();
System.out.println ("\tAccepts only Numeric Values. Try Again");
display();
}
} while (ch == 1);
end();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
display();
}
}
No comments:
Post a Comment