If the inputted is less than 1 error message will be: “INVALID INPUT” This is my source code. import java.util.Scanner; public class NumberToWords {  public String oneToHundredWord(int n) {   String str = "";   while (n != 0) {    if (n == 1) {     str = str + "One ";     n = 0;    } else if (n == 2) {     str = str + "Two ";     n = 0;    } else if (n == 3) {     str = str + "Three ";     n = 0;    } else if (n == 4) {     str = str + "Four ";     n = 0;    } else if (n == 5) {     str = str + "Five ";     n = 0;    } else if (n == 6) {     str = str + "Six ";     n = 0;    } else if (n == 7) {     str = str + "Seven ";     n = 0;    } else if (n == 8) {     str = str + "Eight ";     n = 0;    } else if (n == 9) {     str = str + "Nine ";     n = 0;    } else if (n == 10) {     str = str + "Ten ";     n = 0;    } else if (n == 11) {     str = str + "Eleven ";     n = 0;    } else if (n == 12) {     str = str + "Twelve ";     n = 0;    } else if (n == 13) {     str = str + "Thirteen ";     n = 0;    } else if (n == 14) {     str = str + "Fourteen ";     n = 0;    } else if (n == 15) {     str = str + "Fiftheen ";     n = 0;    } else if (n == 16) {     str = str + "Sixteen ";     n = 0;    } else if (n == 17) {     str = str + "Seventeen ";     n = 0;    } else if (n == 18) {     str = str + "Eighteen ";     n = 0;    } else if (n == 19) {     str = str + "Nineteen ";     n = 0;    } else if (n >= 20 && n < 30) {     str = str + "Tweenty ";     n = n - 20;    } else if (n >= 30 && n < 40) {     str = str + "Thirty ";     n = n - 30;    } else if (n >= 40 && n < 50) {     str = str + "Fourty ";     n = n - 40;    } else if (n >= 50 && n < 60) {     str = str + "Fifty";     n = n - 50;    } else if (n >= 60 && n < 70) {     str = str + "Sixty ";     n = n - 60;    } else if (n >= 70 && n < 80) {     str = str + "Seventy ";     n = n - 70;    } else if (n >= 80 && n < 90) {     str = str + "Eighty ";     n = n - 80;    } else if (n >= 90 && n < 100) {     str = str + "Ninety ";     n = n - 90;    }   }   return str;  }  public String convert(int n) {   String str = "";   while (n != 0) {    if (n >= 1 && n < 100) {     str = str + oneToHundredWord(n);     n = 0;    } else if (n >= 100 && n < 1000) {     str = str + oneToHundredWord(n / 100);     str = str + "Hundred ";     n = n % 100;    } else if (n >= 1000 && n < 10000) {     str = str + oneToHundredWord(n / 1000);     str = str + "Thousand ";     n = n % 1000;    }   }   return str;  }  public static void main(String[] args) throws Exception {   Scanner sc = new Scanner(System.in);   System.out.println("This program will convert inputted integer number into its equivalent in words ");   String str;   int n = 0;   NumberToWords numberToWords = new NumberToWords();   System.out.print("Input an Integer: ");   n = sc.nextInt();   System.out.print("You Entered:" +n+"\n");   if(n>9999) {    System.out.println("INVALID INPUT");   }else {    str = numberToWords.convert(n);    System.out.println("The number in words: " + str);       }  } }

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

If the inputted is less than 1 error message will be: “INVALID INPUT”

This is my source code.

import java.util.Scanner;

public class NumberToWords {

 public String oneToHundredWord(int n) {
  String str = "";
  while (n != 0) {
   if (n == 1) {
    str = str + "One ";
    n = 0;
   } else if (n == 2) {
    str = str + "Two ";
    n = 0;
   } else if (n == 3) {
    str = str + "Three ";
    n = 0;
   } else if (n == 4) {
    str = str + "Four ";
    n = 0;
   } else if (n == 5) {
    str = str + "Five ";
    n = 0;
   } else if (n == 6) {
    str = str + "Six ";
    n = 0;
   } else if (n == 7) {
    str = str + "Seven ";
    n = 0;
   } else if (n == 8) {
    str = str + "Eight ";
    n = 0;
   } else if (n == 9) {
    str = str + "Nine ";
    n = 0;
   } else if (n == 10) {
    str = str + "Ten ";
    n = 0;
   } else if (n == 11) {
    str = str + "Eleven ";
    n = 0;
   } else if (n == 12) {
    str = str + "Twelve ";
    n = 0;
   } else if (n == 13) {
    str = str + "Thirteen ";
    n = 0;
   } else if (n == 14) {
    str = str + "Fourteen ";
    n = 0;
   } else if (n == 15) {
    str = str + "Fiftheen ";
    n = 0;
   } else if (n == 16) {
    str = str + "Sixteen ";
    n = 0;
   } else if (n == 17) {
    str = str + "Seventeen ";
    n = 0;
   } else if (n == 18) {
    str = str + "Eighteen ";
    n = 0;
   } else if (n == 19) {
    str = str + "Nineteen ";
    n = 0;
   } else if (n >= 20 && n < 30) {
    str = str + "Tweenty ";
    n = n - 20;
   } else if (n >= 30 && n < 40) {
    str = str + "Thirty ";
    n = n - 30;
   } else if (n >= 40 && n < 50) {
    str = str + "Fourty ";
    n = n - 40;
   } else if (n >= 50 && n < 60) {
    str = str + "Fifty";
    n = n - 50;
   } else if (n >= 60 && n < 70) {
    str = str + "Sixty ";
    n = n - 60;
   } else if (n >= 70 && n < 80) {
    str = str + "Seventy ";
    n = n - 70;
   } else if (n >= 80 && n < 90) {
    str = str + "Eighty ";
    n = n - 80;
   } else if (n >= 90 && n < 100) {
    str = str + "Ninety ";
    n = n - 90;
   }
  }
  return str;
 }

 public String convert(int n) {
  String str = "";
  while (n != 0) {
   if (n >= 1 && n < 100) {
    str = str + oneToHundredWord(n);
    n = 0;
   } else if (n >= 100 && n < 1000) {
    str = str + oneToHundredWord(n / 100);
    str = str + "Hundred ";
    n = n % 100;
   } else if (n >= 1000 && n < 10000) {
    str = str + oneToHundredWord(n / 1000);
    str = str + "Thousand ";
    n = n % 1000;
   }
  }
  return str;
 }

 public static void main(String[] args) throws Exception {
  Scanner sc = new Scanner(System.in);
  System.out.println("This program will convert inputted integer number into its equivalent in words ");
  String str;
  int n = 0;
  NumberToWords numberToWords = new NumberToWords();
  System.out.print("Input an Integer: ");
  n = sc.nextInt();
  System.out.print("You Entered:" +n+"\n");
  if(n>9999) {
   System.out.println("INVALID INPUT");
  }else {
   str = numberToWords.convert(n);
   System.out.println("The number in words: " + str);
   
  }
 }
}

This program will convert inputted integer number into its equiv
Input an Integer: 0
You Entered: 0
The number in words:
RIITID STICCRSSPITT
mo
del
Transcribed Image Text:This program will convert inputted integer number into its equiv Input an Integer: 0 You Entered: 0 The number in words: RIITID STICCRSSPITT mo del
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
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