Alejandro Loaiza

Greenhorn
+ Follow
since Sep 13, 2013
Merit badge: grant badges
For More
Miami
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alejandro Loaiza

would applying switches to teenWord() and tensWord() still be beneficial?
10 years ago
can someone explain:
private static int decimalDigit(int index, int number)
{

//ALGORITHM:
//Step 1: Divide number by 10, index times
//Step 2: Find the remainder of number from Step 1 with 10
//Step 3: Return the remainder from Step 2
switch ( index )
{
case 2: number /= 10;
case 1: number /= 10;
case 0: return number % 10;
default: return 0;
10 years ago
I also worked on onesWord() and I got:

switch ( digit )
{
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 3: return "three";
case 4: return "four";
case 5: return "five";
case 6: return "six";
case 7: return "seven";
case 8: return "eight";
case 9: return "nine";
default: throw new RuntimeException("Non-Digit " + digit);
}
i erased the random there. would this be correct?
10 years ago
for decimalDigit() i worked up:

switch ( index )
{
case 9: number /= 10;
case 8: number /= 10;
case 7: number /= 10;
case 6: number /= 10;
case 5: number /= 10;
case 4: number /= 10;
case 3: number /= 10;
case 2: number /= 10;
case 1: number /= 10;
case 0: return number % 10;
default: return 0;

I also erased the random there. Would this be correct coming from the Algorithm?
10 years ago
Objectives
1. To understand the functional decomposition strategy for program design.
2. To be able to implement a Java program using methods.

Overview
Write a program to spell a positive integer of up to 3 digits in words. For example:
3 Three 17 Seventeen
90 Ninety 48 Forty Eight
705 Seven Hundred Five 211 Two Hundred Eleven
839 Eight Hundred Thirty Nine 666 Six Hundred Sixty Six

The spelling combines ones-words, teen-words, tens-words and the word Hundred:
Digit Ones-Word Teen-Word Tens-Word
0 Zero Ten Zero
1 One Eleven Ten
2 Two Twelve Twenty
3 Three Thirteen Thirty
4 Four Fourteen Forty
5 Five Fifteen Fifty
6 Six Sixteen Sixty
7 Seven Seventeen Seventy
8 Eight Eighteen Eighty
9 Nine Nineteen Ninety

By splitting the integer into its three digits, each digit can be used to determine part of the spelling. For example, 839 splits into a hundreds-digit of 8, a tens-digit of 3 and a ones-digit of 9; thus the spelling parts are the ones-word Eight, the word Hundred, the tens-word Thirty, and the ones-word Nine - Eight Hundred Thirty Nine

Specific Requirements
1. A completed main() and several method stubs are provided. Run the program as is.
2. Complete the decimalDigit() method. It is called by the threeDigitSpelling() method, so there would be a good place to test decimalDigit(). How?
3. Complete the digit-spelling helper methods, onesWord(), teenWord() and tensWord(). Again, test them by calling them from the threeDigitSpelling() method.
4. Follow the comments to complete an implementation of the threeDigitSpelling() method. Your implementation must use the three digit-spelling helper methods.
5. Test your implementation on several single-digit, two-digit and three-digit integers. Special care for teens and 3-digit numbers like 704 that have 0 for the middle digit!

10 years ago
Hello,
So I have been looking at this weeks code and I am completely dumbfounded. I have added the checklist for this assignment (Assignment4) below as I had trouble attaching them as files. The code you are looking at is what I am supposed to work on. The teacher just added his own work and we are supposed to add whatever the checklist is asking for. So to start the first problem is asking :
2.Complete the decimalDigit() method. It is called by the threeDigitSpelling() method, so there would be a good place to test decimalDigit(). How?

I honestly don't know how to answer this. I have looked through RomanNumeral and I don't see what can help me out here. I need some guidance please. I need some helpful links that is related to this or something. I have crashed twice on this problem. Thank you!



//Program to spell positive 3-digit numberss
//
import java.util.*;
import javax.swing.*;
public class Assignment4
{
public static void main(String[] args)
{
String input; //input buffer
boolean anotherInput = true; //repeat flag

while ( anotherInput )
{
//User enters a 3-digit number, or Cancel to quit
input = JOptionPane.showInputDialog(null, "Enter a Positive Number, 1 ... 999" +
"\nOR click on \"Cancel\" to quit" );
if (input == null) //User hit "Cancel"
anotherInput = false;

else //Number entered
{
//Parse input as an integer
int positive = Integer.parseInt( input );

//Reject integers that are non-positive, or more than 3 digits
if (positive <= 0 || positive > 999)
throw new RuntimeException("Invalid input: " + positive);

//Display the spelling (in words) of the input integer
String spelling = threeDigitSpelling( positive );

JOptionPane.showMessageDialog(null, positive + " " + spelling);
}
}
}

//Return the spelling (in words) of any positive number up to 3 digits
//Parameter number : any positive whole number 1 ... 999
private static String threeDigitSpelling(int number)
{
//Obtain the individual digits of the number
int hundreds = decimalDigit(2, number);
int tens = decimalDigit(1, number);
int ones = decimalDigit(0, number);

//The spelling that will be returned
String words = "";

//Intrepret the hundreds digit to extend the spelling


//Interpret the tens digit to extend the spelling.
//There are three different cases:
// a) tens > 1, b) tens == 1, c) tens == 0


//Interpret the ones digit to extend the spelling


//Return the spelling
String[] verse = {"Hickory Dickory Dock!",
"The Mouse Ran Up The Clock!",
"The Clock Struck One!",
"The Mouse Ran Down!",
"Hickory Dickory Dock!" };
return verse[ (new Random()).nextInt(verse.length) ];
}


//Helper method: Returns the ones-word spelling of a single digit
// Zero, One, Two, ..., Nine
//Parameter digit : 0 ... 9, identifies the desired ones-word
private static String onesWord(int digit)
{
return "" + digit;
}


//Helper method: Return the teen-word spelling of a single digit
// Ten, Eleven, Twelve, ..., Nineteen
//Parameter digit : 0 ... 9, identifies the desired teen-word
private static String teenWord(int digit)
{
return "" + digit;
}


//Helper method: Return the tens-word spelling of a single digit
// Zero, Ten, Twenty, ..., Ninety
//Parameter digit : 0 ... 9, identifies the desired tens-word
private static String tensWord(int digit)
{
return "" + digit;
}

//Helper method: Return a digit of any positive integer
//Parameter index : indexes the desired digit, 0 = least significant
//Parameter number : the integer whose digit is required
//Example: decimalDigit(3, 57419) returns 7
private static int decimalDigit(int index, int number)
{
//ALGORITHM:
//Step 1: Divide number by 10, index times
//Step 2: Find the remainder of number from Step 1 with 10
//Step 3: Return the remainder from Step 2

return (new Random()).nextInt(10);
}
}
10 years ago
So I'm on my last part of my assignment and I'm stuck on constructing a customers monthly statement if they go over the specific amount of hours they chose from the Packages and it would display the amount of money they would have saved if they chose Package B or Package C. That's only if they go over the hours. In my code, I seem to not be able to use:

if (hours < baseHours) from my internetServiceCharges() so I can calculate. The assignment question is this :

4. Challenge 14: The modifications to your program should be made entirely in main(). You must add statements to perform additional calculations, and extend the customer’s statement with additional information. You must use several if-statements. Test your program all over again to make sure it works as specified. For example:

Total Charges for 50 Package A hours: $89.95
A Package B Customer would have saved $46.0
A Package C Customer would have saved $70.0


I have been working on this for several hours and I broke down. I know the area where I am working at *I am flagging the code!* is off/wrong
because I need several IF's, but where??? I don't understand this at all. Would I be using IF ELSE here because one of my classmates said yes but it's not specified....?

This is my code and I'm extremely sorry if all of this looks like a major mess lol but please help me out with this last bit of code:


10 years ago
I checked out your links and I understand the code, I just don't understand how to apply it. I'm a real newbie and this was an assignment due yesterday and I'm crashing to understand this....so again, I saw the link, understand the code, but I don't know how or where to apply the code.
10 years ago
This program prompts the user to enter the cost of an item and the amount tendered for payment. It displays two output windows.
1. Convert the change to whole cents, and use int / and % to get Dollars and Cents
2. Use / and % to get the numbers of each bill from the Dollars, coins from the Cents
3. Hint: Rounding can eliminate unwanted digits, and correct for a missing cent.

This is my program. I tried to do what I can do but there are some problems, namely the fact that the product comes out with a bunch of decimals places after a bunch of variables, but i can't seem to figure it out. I'm stuck like entering 17.25 for the cost of item and then entering 20.21 for tendering. I'm stuck. Please help

10 years ago