Answered step by step
Verified Expert Solution
Question
1 Approved Answer
use this template import java.util.Scanner; public class IntegerName { / * * Turns a number into its English name. @param number a positive integer <
use this template import java.util.Scanner;
public class IntegerName
Turns a number into its English name.
@param number a positive integer
@return the name of the number eg "two hundred seventy four"
public static String intNameint number
int part number; The part that still needs to be converted
String name ; The name of the number
if part
Recursively call intName Hint: use return
String thousandsPart intNamepart ;
name thousandsPart thousand ;
part part ;
if part
name digitNamepart hundred";
part part ;
if part
name name tensNamepart;
part part ;
else if part
name name teenNamepart;
part ;
if part
name name digitNamepart;
return name;
Turns a digit into its English name.
@param digit an integer between and
@return the name of digit one "nine"
public static String digitNameint digit
if digit return "one";
if digit return "two";
if digit return "three";
if digit return "four";
if digit return "five";
if digit return "six";
if digit return "seven";
if digit return "eight";
if digit return "nine";
return ;
Turns a number between and into its English name.
@param number an integer between and
@return the name of the given number ten "nineteen"
public static String teenNameint number
if number return "ten";
if number return "eleven";
if number return "twelve";
if number return "thirteen";
if number return "fourteen";
if number return "fifteen";
if number return "sixteen";
if number return "seventeen";
if number return "eighteen";
if number return "nineteen";
return ;
Gives the name of the tens part of a number between and
@param number an integer between and
@return the name of the tens part of the number twenty "ninety"
public static String tensNameint number
if number return "ninety";
if number return "eighty";
if number return "seventy";
if number return "sixty";
if number return "fifty";
if number return "forty";
if number return "thirty";
if number return "twenty";
return ;
public static void mainString args
Scanner in new ScannerSystemin;
int number innextInt;
System.out.printlnintNamenumber;
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