Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Fix this Java code and make it run sucessfulin a Java program. import java.util.Scanner; public class timetowordsconversaion { public static void main ( String [
Fix this Java code and make it run sucessfulin a Java program.
import java.util.Scanner;
public class timetowordsconversaion
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printlnWelcome to the Date to Words Converter!";
while true
System.out.print
Enter a date in format MMDDYYYY ;
String input scanner.nextLine;
String parts input.split;
int month Integer.parseIntparts;
int day Integer.parseIntparts;
int year Integer.parseIntparts;
if month month
System.out.printlnInvalid month range. Please enter a valid month.";
continue;
if day day
System.out.printlnInvalid day range. Please enter a valid day.";
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 ;
int yearPart year ;
if yearPart
yearString "zero zero";
else if yearPart
yearString "zero convertNumberToWordyearPart;
else
yearString convertNumberToWordyearPart;
System.out.printlnmonthsmonth daysday convertNumberToWordcentury yearString;
public static String convertNumberToWordint 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
return onesnumber;
else if number
return teensnumber ;
else if number
return tensnumber onesnumber ;
else
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started