A community for students.
Here's the question you clicked on:
 0 viewing
galacticwavesXX
 2 years ago
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
galacticwavesXX
 2 years ago
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

This Question is Closed

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0my 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
 2 years ago
Best ResponseYou've already chosen the best response.1You can use division and subtraction to split off parts.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0So 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?

e.mccormick
 2 years ago
Best 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...

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0im 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0the 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");

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

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1That 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0So 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
 2 years ago
Best ResponseYou've already chosen the best response.1Either 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0ok 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;

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0since it all has to be keyboard input

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1To 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
 2 years ago
Best ResponseYou've already chosen the best response.1Hmmm.... 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)

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Then use that to find the cents...

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1or to find the coins...

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0ohh 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
 2 years ago
Best ResponseYou've already chosen the best response.1Yah, the 100 is to change from a decimal to an int. Then everything else you did works.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0so i input int coin25 = newCents/25; newCents %= 25;

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Cent 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0ohh so divide everything by 100 then

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

e.mccormick
 2 years ago
Best 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.

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

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

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0i meant int coin25

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

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

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Oh, 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0Ohh 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
 2 years ago
Best ResponseYou've already chosen the best response.1I just meant for you to try it so you would know what I am talking about.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0int 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)

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1For 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)

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Note how it messes up the bottom? Whee.

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1I 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
 2 years ago
Best ResponseYou've already chosen the best response.1If you have feet to inches or weight chanegs or anything with a unit change, that principal works.

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

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

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0lol 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
 2 years ago
Best ResponseYou've already chosen the best response.1Hehe. 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0Yeah 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
 2 years ago
Best ResponseYou've already chosen the best response.1Well, calc uses evberything down to 1+1=2!

e.mccormick
 2 years ago
Best 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. =)

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

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Yah. 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.

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0I'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
 2 years ago
Best ResponseYou've already chosen the best response.1Yah, 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
 2 years ago
Best ResponseYou've already chosen the best response.1This is one representation of the concept: http://www.alglib.net/matrixops/sparse.php

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0Exactly makes solving problems less strenuous

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Another 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.

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1http://openstudy.com/study#/updates/51677e75e4b050ab14bf429e

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0Ok, 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
 2 years ago
Best ResponseYou've already chosen the best response.1I only went to intro linear myself, so there are tons I don't get. Hehe.

e.mccormick
 2 years ago
Best ResponseYou've already chosen the best response.1Well, I am going to sneak off. Have fun!

galacticwavesXX
 2 years ago
Best ResponseYou've already chosen the best response.0you too thanks for the help!
Ask your own question
Sign UpFind more explanations on OpenStudy
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.