
Create a Java program that prompts the user to input a date in the format MM/DD/YYYY. The program should convert the entered date into its verbal representation according to the following guidelines:
- Print the English name of the month.
- Print the English representation of the day (e.g., first, second, ..., thirty-first).
- Display the English representation of the year, which consists of two parts: a century part ranging from 10 to 99, and a year part in the range from 0 to 99. Ensure to include a "zero" suffix when printing single-digit years.
For example:
- The year 2003 should be represented as twenty zero three.
- The year 1992 should be represented as nineteen ninety-two.
While this may seem like an unconventional
Now use my code and rewrite the java program so that it includes what is missing in the assignment.
import java.util.Scanner;
public class TimeToWordsConversion {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Welcome to the Date to Words Converter!");
while (true) {
System.out.print("Enter a date in format MM/DD/YYYY > ");
String input = scanner.nextLine();
String[] parts = input.split("/");
int month = Integer.parseInt(parts[0]);
int day = Integer.parseInt(parts[1]);
int year = Integer.parseInt(parts[2]);
if (month < 1 || month > 12) {
System.out.println("Invalid month range. Please enter a valid month.");
continue;
}
if (day < 1 || day > 31) {
System.out.println("Invalid day range. Please enter a valid day.");
continue;
}
if (year < 0) {
System.out.println("Invalid year. Please enter a valid year.");
continue;
}
String[] months = {"", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
String[] days = {"", "first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth", "thirteenth", "fourteenth", "fifteenth", "sixteenth", "seventeenth", "eighteenth", "nineteenth", "twentieth", "twenty first", "twenty second", "twenty third", "twenty fourth", "twenty fifth", "twenty sixth", "twenty seventh", "twenty eighth", "twenty ninth", "thirtieth", "thirty first"};
String yearString = "";
int century = year / 100;
int yearPart = year % 100;
if (yearPart == 0) {
yearString = "zero zero";
} else if (yearPart < 10) {
yearString = "zero " + convertNumberToWord(yearPart);
} else {
yearString = convertNumberToWord(yearPart);
}
System.out.println(months[month] + " " + days[day] + ", " + convertNumberToWord(century) + " " + yearString);
}
}
public static String convertNumberToWord(int number) {
String[] ones = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
String[] tens = {"", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"};
String[] teens = {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
if (number < 10) {
return ones[number];
} else if (number < 20) {
return teens[number - 10];
} else if (number < 100) {
return tens[number / 10] + " " + ones[number % 10];
} else {
return convertNumberToWord(number / 100) + " hundred " + convertNumberToWord(number % 100);
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps

- 17.Write a Java program that prompts the user to input an integer greater than 0 which represents the size/height of the triangle shape. The program should print the following triangle shape according to the user input by alternating 'f' and '+' characters. Invalid error message must be displayed if the size is less than 1. Example: if the size of the shape = 4, then the p program should output: ! !+! !+!+! 1+1+1+1arrow_forwardn this lab, you complete a prewritten Python program for a carpenter who creates personalized house signs. The program is supposed to compute the price of any sign a customer orders, based on the following facts: The charge for all signs is a minimum of $35.00. The first five letters or numbers are included in the minimum charge; there is a $4 charge for each additional character. If the sign is make of oak, add $20.00. No charge is added for pine. Black or white characters are included in the minimum charge; there is an additional $15 charge for gold-leaf lettering.arrow_forward17.Write a Java program that prompts the user to input an integer greater than 0 which represents the size/height of the triangle shape. The program should print the following triangle shape according to the user input by alternating 'f' and '+' characters. Invalid error message must be displayed if the size is less than 1. Example: if the size of the shape = 4, then the p program should output: ! !+! !+!+! 1+1+1+1arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





