0% found this document useful (0 votes)
43 views8 pages

Activity5 Cabuhat V H S

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views8 pages

Activity5 Cabuhat V H S

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Activity #5 – Converting Input Integer to Words

NAME: CABUHAT, VINCENT HANAMICHI S. SECTION: CEIT-37-301A

1. Create a program to input integer from 1 to 9,999 (Range) and to output the inputted
number in words.

Required screen Layout/output:


This program will convert inputted integer number into its equivalent in words
Input an Integer : 2345 (Sample)

You entered : 2345


The number in words : Two Thousand Three Hundred Forty Five

2. Input Integer using the following data:


a. Less than 1
b. Greater than 9,999
c. Range from Eleven to Nineteen (11 – 19)
d. 218
e. 2345
f. 3000

*Note: If input is out of range, error message will be: “INVALID INPUT”

3. Screenshot/Print Screen the outputs of your programs.


4. Submit the source code (Java Program codes) and 6 different sample outputs in PDF
format.

***NOTE: DO NOT USE ARRAYS for your solutions.

Filename: Activity5_Lastname_Firstname(Initial)_Middle Initial.pdf

(e.g. Activity5_Marcos_B_B.pdf)
SOURCE CODE:
import java.util.Scanner;
public class ActFive_Cabuhat {
public static void main(String[] args) {

Scanner scan = new Scanner (System.in);


System.out.print("This program will convert inputted integer into its
equivalent words.");

System.out.print("\n\nInput an integer number :");

int x = scan.nextInt();

int thou;
int hund;
int teens;
int tens;
int ones;

if ((x <= 9999 && x >= 1000)){

System.out.println("You entered a four(4) digit number.");


System.out.println("The number is\t\t: "+x);
System.out.print("The number in words\t: ");
}

else if ((x <= 999 && x >= 100)){

System.out.println("You entered a three(3) digit number.");


System.out.println("The number is\t\t: "+x);
System.out.print("The number in words\t: ");
}

else if ((x <= 99 && x >= 10)){

System.out.println("You entered a two(2) digit number.");


System.out.println("The number is\t\t: "+x);
System.out.print("The number in words\t: ");
}

else if ((x <= 9 && x >=1)){

System.out.println("You entered a one(1) digit number.");


System.out.println("The number is\t\t: "+x);
System.out.print("The number in words\t: ");
}

else {

System.out.println("\nINVALID INPUT!");

if ( x >= 100 && x <= 9999)


{
thou = x/1000;
x=x%1000;
hund = x/100;
x=x%100;

switch (thou) {

case 1:System.out.print("One Thousand ");break;


case 2:System.out.print("Two Thousand ");break;
case 3:System.out.print("Three Thousand ");break;
case 4:System.out.print("Four Thousand ");break;
case 5:System.out.print("Five Thousand ");break;
case 6:System.out.print("Six Thousand ");break;
case 7:System.out.print("Seven Thousand ");break;
case 8:System.out.print("Eight Thousand ");break;
case 9:System.out.print("Nine Thousand ");break;

switch (hund) {

case 1:System.out.print("One Hundred ");break;


case 2:System.out.print("Two Hundred ");break;
case 3:System.out.print("Three Hundred ");break;
case 4:System.out.print("Four Hundred ");break;
case 5:System.out.print("Five Hundred ");break;
case 6:System.out.print("Six Hundred ");break;
case 7:System.out.print("Seven Hundred ");break;
case 8:System.out.print("Eight Hundred ");break;
case 9:System.out.print("Nine Hundred ");break;
}

if (x >10 && x < 20)

tens = x/10;
ones = x;
teens = x%10;

switch (teens) {

case 1:System.out.print("Eleven ");break;


case 2:System.out.print("Twelve ");break;
case 3:System.out.print("Thirteen ");break;
case 4:System.out.print("Fourteen ");break;
case 5:System.out.print("Fifteen ");break;
case 6:System.out.print("Sixteen ");break;
case 7:System.out.print("Seventeen ");break;
case 8:System.out.print("Eighteen ");break;
case 9:System.out.print("Nineteen ");break;

}
}

else {

tens = x/10;
x = x%10;
ones = x;

switch (tens) {

case 1:System.out.print("Ten ");break;


case 2:System.out.print("Twenty ");break;
case 3:System.out.print("Thirty ");break;
case 4:System.out.print("Forty ");break;
case 5:System.out.print("Fifty ");break;
case 6:System.out.print("Sixty ");break;
case 7:System.out.print("Seventy ");break;
case 8:System.out.print("Eighty ");break;
case 9:System.out.print("Ninety ");break;
}

{
switch (ones) {

case 1:System.out.print("One ");break;


case 2:System.out.print("Two ");break;
case 3:System.out.print("Three ");break;
case 4:System.out.print("Four ");break;
case 5:System.out.print("Five ");break;
case 6:System.out.print("Six ");break;
case 7:System.out.print("Seven ");break;
case 8:System.out.print("Eight ");break;
case 9:System.out.print("Nine ");break;

default:System.out.println(" ");break;
}
if(x>9999)
{
System.out.println("INVALID INPUT!");
}
}
}
}
}
SAMPLE OUTPUT:

A. LESS THAN 1

B. GREATER THAN 9,999


C. RANGE FROM ELEVEN TO NINETEEN (11 – 19)

D. 218
E. 2345

F. 3000

You might also like