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

- anonymous

- katieb

See more answers at brainly.com

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your **free** account and access **expert** answers to this

and **thousands** of other questions

- anonymous

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;

- e.mccormick

You can use division and subtraction to split off parts.

- anonymous

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?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

## More answers

- e.mccormick

$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...

- anonymous

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.

- anonymous

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");

- anonymous

@thomaster can you help me on how to solve for coins in my java program?

- e.mccormick

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.

- anonymous

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?

- e.mccormick

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.

- anonymous

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;

- anonymous

since it all has to be keyboard input

- e.mccormick

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;

- e.mccormick

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)((amount-newAmount)*100)

- e.mccormick

Then use that to find the cents...

- e.mccormick

or to find the coins...

- anonymous

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!!

- e.mccormick

Yah, the 100 is to change from a decimal to an int. Then everything else you did works.

- anonymous

so i input
int coin25 = newCents/25;
newCents %= 25;

- e.mccormick

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.

- anonymous

ohh so divide everything by 100 then

- e.mccormick

Well, you want to go from a decimal to a whole number, so multiply by 100.

- e.mccormick

\(\dfrac{x}{100}\cdot 100 = x\) And you want x cents.
\(.11 \implies \dfrac{11}{100}\) and you want 11.

- e.mccormick

Because you are going from .11 dollars to 11 cents. So really, unit conversion.

- anonymous

ok so i should input
int quarter = newCents * 100;
that is what your saying

- anonymous

i meant int coin25

- e.mccormick

No, because newCents is the entire cents. Then you use the same thing you did before:
int coin25 = newCents/25;
newCents %= 25;

- e.mccormick

Repeat for 10 and 5, no need to repeat for 1. Just use the %5 to get pennies.

- e.mccormick

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)((amount-newAmount)*100)
```
int newAmount; //To hold new amount
newAmount = (int)amount;
int newCents; // To hold the cents
newCents = (int)((amount-newAmount)*100)
Try to copy and paste both of those.

- anonymous

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?

- e.mccormick

I just meant for you to try it so you would know what I am talking about.

- anonymous

int newAmount; //To hold new amount
newAmount = (int)amount;
int newCents; // To hold the cents
newCents = (int)((amount-newAmount)*100)
int newAmount; //To hold new amount
newAmount = (int)amount;
int newCents; // To hold the cents
newCents = (int)((amount-newAmount)*100)

- e.mccormick

For me it does this:
int newAmount; //To hold new amount
newAmount = (int)amount;
int newCents; // To hold the cents
newCents = (int)((amount-newAmount)*100)
int newAmount; //To hold new amount newAmount = (int)amount; int newCents; // To hold the cents newCents = (int)((amount-newAmount)*100)

- e.mccormick

Note how it messes up the bottom? Whee.

- e.mccormick

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¢\)

- e.mccormick

If you have feet to inches or weight chanegs or anything with a unit change, that principal works.

- anonymous

Yup i see it, i didnt know it made that much of a difference. so many things to know

- e.mccormick

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.

- anonymous

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

- e.mccormick

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.

- anonymous

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

- e.mccormick

Well, calc uses evberything down to 1+1=2!

- e.mccormick

\(\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. =)

- anonymous

hahaha of course integration was fun even though there were so many kind of ways to do it, depending on the question given

- e.mccormick

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.

- anonymous

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

- e.mccormick

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.

- e.mccormick

This is one representation of the concept:
http://www.alglib.net/matrixops/sparse.php

- anonymous

Exactly makes solving problems less strenuous

- e.mccormick

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.

- anonymous

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

- e.mccormick

I only went to intro linear myself, so there are tons I don't get. Hehe.

- e.mccormick

Well, I am going to sneak off. Have fun!

- anonymous

you too thanks for the help!

Looking for something else?

Not the answer you are looking for? Search for more explanations.