NoPistons -Mazda Rx7 & Rx8 Rotary Forum

NoPistons -Mazda Rx7 & Rx8 Rotary Forum (https://www.nopistons.com/)
-   Insert BS here (https://www.nopistons.com/insert-bs-here-12/)
-   -   Need Java Help Stat! (https://www.nopistons.com/insert-bs-here-12/need-java-help-stat-33911/)

Eyxom 02-16-2004 11:33 AM

I need a hand with Java. This is what I have to do. If anyone can put me on the right direction as to how to set it up, I'd appreciate it.



temp = cashPaid - purchaseAmount;

temp = temp - int (temp) + 0.00001;

change = int (temp * 100);



The file ComputeChange.java contains the beginning code for the project. You need to create a project called change inside of your JavaProjects folder and then save the file in this folder. The program

Prompts the user for the following information.



Amount of purchase

Amount of cash tendered

Calculates the correct change.

Prints the amount of change.

Open the program and run the program with the following data:



Amount of purchase = 23.06

Cash tendered = 30.00



You just received an email from a friend of yours who heard that you were learning to program and wants you to change this program so that in addition to printing the correct change in dollars and cents, it also prints the number of dollars, and the number of each type of coin. When you run your program with the above data you should get the following output:



Amount of purchase = 23.06

Cash tendered = 30.00



Change = $6.94



You will need



6 dollars

3 quarters

1 dime

1 nickel

4 pennies



Do not worry about singular versus plural endings, i.e. quarter/quarters. Also make sure that if the change is something like $4.50, your program will print the ending zero.



Thanks to anyone that can help.



- Anthony

FrestyleFC3S 02-16-2004 11:34 AM

:a splode:

UniqueTII 02-16-2004 01:03 PM

One way would be to take the change and do a mod (I think the modulus operator in Java is %) and division for each amount. It'd be easier if you multiply the change by 100 first, so you can use all integers. For example, if your change is $1.89, you'd multiply by 100 to get 189. Then you'd divide 189/100 to get one dollar, then use 189%100 to get 89. For quarters, you'd divide 89/25 to get 3, then do 89%25 to get 14, and so on.



As for the actual code, I could write it in C++ or VB, but I haven't done Java in years and years.

Baldy 02-16-2004 01:13 PM


Originally Posted by FrestyleFC3S' date='Feb 16 2004, 12:34 PM
:a splode:

I concur.



Good luck.

Eyxom 02-16-2004 07:10 PM

* @author Anthony Pastorini

* @created 2/16/04

*/



import chn.util.*;



public class ComputeChange

{

/**

* The main program for the Change class

*

* @param args The command line arguments - not used

*/

public static void main(String[] args)

{

double purchase, cashPaid, temp;

int change, remainder, dollars, quarters, dimes, nickels, pennies;



ConsoleIO keyboard = new ConsoleIO();



System.out.print("Enter amount of purchase --> ");

purchase = keyboard.readDouble();

System.out.print("Enter amount of cash paid --> ");

cashPaid = keyboard.readDouble();



temp = cashPaid - purchase;

dollars = (int) temp;

temp = temp - (int)temp + 0.00001;

change = (int)(temp * 100);



remainder = dollars;

quarters = change/25;

dimes = (change/25)/10;

nickels = ((change/25)/10)/5;

pennies = (((change/25)/10)/5)/1;



System.out.println("\n$" + dollars + "." + change);

System.out.println("\nDollars " +remainder + "\nQuarters " +quarters + "\nDimes " +dimes + "\nNickels " +nickels + "\nPennies " +pennies);





}



I would greatly appreciate anyone who can tell me what's wrong with that... The dollars and quarters are right, but the dimes are wrong. And if the dimes are wrong, the rest are wrong. Any help would be great!



- Anthony

UniqueTII 02-16-2004 07:13 PM

Dimes would be (Change - (25*Quarters))/10 and so on

UniqueTII 02-16-2004 07:17 PM

Example, if your change is .89 you'd have:



3 quarters

1 dime

4 pennies



quarters = change/25; would give you quarters = 3. Now, if you use the mod operator like I originally suggested, you'd get change%25=14 so dimes =14/10 = 1. Otherwise, you can use dimes = (Change - (25*Quarters))/10 like I suggested above and get dimes =(89-(25*3))/10 = (89-75)/10 = 14/10 = 1 and then so on for the rest of the coins.

teknics 02-16-2004 07:25 PM

i have one thing to say.



**** java.



kevin.

Eyxom 02-17-2004 10:46 AM

Aaaahhhhh... Yes! I forgot modulus was used for remainders! https://www.nopistons.com/forums/pub...1047683664.gif I was wondering why my quarters amount got f*cked up when I used it. lol time to re-work the equations.



I'm such a tard...



Thanks for the help man. It's greatly appreciated.

Eyxom 02-17-2004 10:48 AM


Originally Posted by teknics' date='Feb 16 2004, 05:25 PM
i have one thing to say.



**** java.



kevin.

Java = $$$$ WIN $$$$


All times are GMT -5. The time now is 01:40 PM.


© 2024 MH Sub I, LLC dba Internet Brands