Week 7 - Laboratory Activity: A. Using Java Arrays Problem
Week 7 - Laboratory Activity: A. Using Java Arrays Problem
Objectives:
a. Declare and create one-dimensional arrays
b. Access array elements
c. Determine the number of elements in an array
Problem: Write a Java Application that will let the user enter a Number from 0 – 999999 (Note:
Maximum of six digits only) and converts the number to its word form. For
example, if the number entered is 123, the java program should print “One
Hundred Twenty-Three” and so on.
Notes:
a. You may use any of the following classes for User Input: BufferedReader, JOptionPane or
Scanner.
b. Use Conditional Statements, Looping Statements (if necessary) and Arrays.
c. For the output, you may also use any of the classes mentioned in letter “a”.
Step 2. Write the intended program for the problem. Refer to the “Notes” above for the Input
and Output requirements.
package week7labact;
import java.util.Scanner;
if (xintnumbr == 0) {
return "zero";
}
if (xintnumbr < 0) {
// converts number to a string
String numberStr = "" + xintnumbr;
numberStr = numberStr.substring(1);
// add minus before the number and convert the rest of number
return "minus " + numberToWord(Integer.parseInt(numberStr));
}
// divisible by 1 thousand
if ((xintnumbr / 1000) > 0) {
words += numberToWord(xintnumbr / 1000) + " thousand ";
xintnumbr %= 1000;
}
// divisible by 1 hundred
if ((xintnumbr / 100) > 0) {
words += numberToWord(xintnumbr / 100) + " hundred ";
xintnumbr %= 100;
}
if (xintnumbr > 0) {
b. Screenshots of the Final Output (At least FIVE sample output) (25 points)
Note: Include in the screenshots one sample output for “Incorrect Input (Max. of 6 digits only!)”.
c. Selfie Picture with the output. Note: Be sure the screen output is visible and not
blurred or too dark. (5 points)