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 programming task, it can be beneficial if you intend to use the resulting string with a text-to-voice converter to audibly communicate the result. 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);         }     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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 programming task, it can be beneficial if you intend to use the resulting string with a text-to-voice converter to audibly communicate the result.

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);
        }
    }
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Top down approach design
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education