Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
galacticwavesXX
Group Title
Can someone help me with my java code?
i am stuck on how to come up with an mathematical equation that can take any amount between 0  999.99 and break it into smaller monetary amounts
 11 months ago
 11 months ago
galacticwavesXX Group Title
Can someone help me with my java code? i am stuck on how to come up with an mathematical equation that can take any amount between 0  999.99 and break it into smaller monetary amounts
 11 months ago
 11 months ago

This Question is Closed

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
my code so far is import java.util.Scanner; //Need Scanner class public class Money { public static void main(String[] args) { double amount; //To hold the monetary amount int newAmount; //To hold the total amount of Dollars double amount_Of_Coins; //To hold the total amount of coins int bill20, bill10, bill5, bill1; //To hold the units of bills of the monetary amount int coin25, coin10, coin5,coin1; //To hold the units of coins of the monetary amount Scanner keyboard = new Scanner(System.in); //Ask the user for the monetary amount System.out.println("Enter a monetary amount between 0  999.99: "); amount = keyboard.nextDouble(); newAmount = (int)amount;
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
You can use division and subtraction to split off parts.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
So for the division i can use to split the left side and right side of a value....supposing the value was 36.41. Subtraction could be used to calculate the amount of coins there are for quarters, dimes, nickels and pennies, right?
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
$432.11 First, *100 to get it into integer math. 43211 Divide by 10000 to find the number of 100 bills. b100 = 4 Subtract 4*b100 to get 3211. Divide by 2000 to get the number of $20 bills. b20=1 and so on...
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
im sorry openstudy just stopped working for the longest so i couldn't do anything but try to get the code working a little. I got the dollar bills to work fine...now im stuck on the coins.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
the code i have so far is: import java.util.Scanner; //Need Scanner class public class Money { public static void main(String[] args) { double amount; //To hold the monetary amount Scanner keyboard = new Scanner(System.in); //Ask the user for the monetary amount System.out.println("Enter a monetary amount between 0  999.99: "); amount = keyboard.nextDouble(); int newAmount; //To hold new amount newAmount = (int)amount; int bill20 = newAmount/20; newAmount %= 20; int bill10 = newAmount/10; newAmount %= 10; int bill5 = newAmount/5; newAmount %= 5; int bill1 = newAmount/1; newAmount %= 1; System.out.println(bill20 + " amount of 20 dollar bills"); System.out.println(bill10 + " amount of 10 dollar bills"); System.out.println(bill5 + " amount of 5 dollar bills"); System.out.println(bill1 + " amount of 1 dollar bills");
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
@thomaster can you help me on how to solve for coins in my java program?
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
That is why I said start with multiplying by 100. But if you get it don to just the coins, you could multiply by 100 there and then it is the same basic thing.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
So using your example of $432.11, for doing it with the dollar bills i'm multiplying 432.11 * 100. or just in the form .11 * 100 part?
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Either way works, but you have the dollars work out. So you take the remainder, .11, and go from there. *100 and it will be cents as in per 100. /25 for quarters, mode 25 to get what is left to get the dimes, etc.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
ok so i can put in a mathematical operation such as dollar coin = newAmount  amount; since the user has to put an amount and see if the monetary system runs then get quarter = (coin * 100)/25; quarter %= 25;
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
since it all has to be keyboard input
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
To coninue the way you had it.... int bill1 = newAmount/1; newAmount %= 1; newAmount *= 100; int coin25 = newAmount/25; newAmount %= 25; int coin10 = newAmount/10; newAmount %= 10; int coin5 = newAmount/5; int coin1 = newAmount % 5;
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Hmmm.... looks like you already stripped the ints... so... more like: int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100)
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Then use that to find the cents...
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
or to find the coins...
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
ohh okay that makes more sense.... trying to calculate for the coins was tricky...i didnt know you had to multiply it by 100. but thanks man, you help me out a LOT!!
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Yah, the 100 is to change from a decimal to an int. Then everything else you did works.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
so i input int coin25 = newCents/25; newCents %= 25;
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Cent and percent have the same base. Per Centum, or Per 100. Well, per 100 has another representation: \(\dfrac{x}{100}\) It is the same thing about converting percentage.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
ohh so divide everything by 100 then
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Well, you want to go from a decimal to a whole number, so multiply by 100.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
\(\dfrac{x}{100}\cdot 100 = x\) And you want x cents. \(.11 \implies \dfrac{11}{100}\) and you want 11.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Because you are going from .11 dollars to 11 cents. So really, unit conversion.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
ok so i should input int quarter = newCents * 100; that is what your saying
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
i meant int coin25
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
No, because newCents is the entire cents. Then you use the same thing you did before: int coin25 = newCents/25; newCents %= 25;
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Repeat for 10 and 5, no need to repeat for 1. Just use the %5 to get pennies.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Oh, and you may notice that what you type here collapses when people paste it. If you put ``` above and below on a seperate line it will do proper coding. ``` int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100) ``` int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100) Try to copy and paste both of those.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
Ohh okay i get it now, so many little things to look into and know....i need to practice more on these kinds of programs you want me to copy and paste it here or on my program?
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
I just meant for you to try it so you would know what I am talking about.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100) int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100)
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
For me it does this: int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100) int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amountnewAmount)*100)
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Note how it messes up the bottom? Whee.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
I wanted to do one detailed example because this actually applies to anything. Physics, geology, etc. you can use this. If you think of it in unit conversion terms it is a ratio: 1$:100¢ Therefore to find x$ in ¢, you set thing up as fractions. Now, to convert, the units you convert from must cancel. \(.11$ \implies \dfrac{11$}{100}\) Because $ is on the top, I need to set up my cancel ratio with it on the bottom: \(\dfrac{11$}{100}\cdot \dfrac{100¢}{1$}\implies \) \( \dfrac{11\bcancel{$}}{\cancel{100}} \cdot \dfrac{\cancel{100}¢}{1\bcancel{$}} \implies\) \( \dfrac{11}{1}\cdot \dfrac{¢}{1}=11¢\)
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
If you have feet to inches or weight chanegs or anything with a unit change, that principal works.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
Yup i see it, i didnt know it made that much of a difference. so many things to know
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Well, it is just a general principal. In this case you are using it to get integer math for cents. Cause it makes sense... hehe.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
lol yeah its just when you program sometimes those general concepts slip out because of all the new language you need to remember or are trying to use properly
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Hehe. And it is a general concept in math and perhaps any other science you learned. That is why they teach all that math. It lets you use the general concepts in other things.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
Yeah with all the math classes i've taken they brought back geometry and algebra concepts but they weren't hard.....it's only the trig applied in calculus that kills integrity
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Well, calc uses evberything down to 1+1=2!
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
\(\int x\rm dx\) when you do that, you add one to the power, right? \(\int x\rm dx\implies \int x^1\rm dx\implies \dfrac{x^{1+1}}{1+1}+c\) So in calculus you use 1+1=2. =)
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
hahaha of course integration was fun even though there were so many kind of ways to do it, depending on the question given
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Yah. I just enjoy pointing out that everything finally comes together in math at about trig. From then on, it is "And you get to use everything you learned from preeschool on at this point." Parts of math before that seem unrelated or distant cousins at times. Once you hit trig, you use everything all at once. And calculus is the same, and inclused the trig. Linear Algebra can be used with calculus in it.... so really nasty at times. And so on.
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
I'm in linear algebra right now.....Matrices seems too run the world and i just found out that Google is composed of matrices itself we are doing application problems to figure out if it has solutions or not, depending if the system is consistent or not working with matrices is a lot faster i might say
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Yah, it it invertable... does it have a determinant. Presto. Many qustions answered right there. Google uses a hash map. Hash maps can be represnted in matrices.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
This is one representation of the concept: http://www.alglib.net/matrixops/sparse.php
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
Exactly makes solving problems less strenuous
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Another thing is you have rules about what is done. So you can apply the rules to the equation and get the result... let me see if I can find this thing. It was like an early question ansewered. Was not thinking when I did it the first time and redid it for the guy properly.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
http://openstudy.com/study#/updates/51677e75e4b050ab14bf429e
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
Ok, i'm still trying to understand this sparse matrices concept but i'm looking at it and i'm like i haven't learned some these things yet
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
I only went to intro linear myself, so there are tons I don't get. Hehe.
 11 months ago

e.mccormick Group TitleBest ResponseYou've already chosen the best response.1
Well, I am going to sneak off. Have fun!
 11 months ago

galacticwavesXX Group TitleBest ResponseYou've already chosen the best response.0
you too thanks for the help!
 11 months ago
See more questions >>>
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.