1. Member
Join Date
Apr 2012
Posts
1
Rep Power
0

## Some java assistance

Evening friends. I've been in this Java 1 class for a few weeks. Prior to this I knew nothing of java and my logic and math intelligence is quite low. So I've come here for some assistance. Our current assignment is this:

Write an application that prompts for and reads a double value representing a monetary amount. Then determine the fewest number of each bill and coin needed to represent the amount, starting with the highest (assume that a twenty-dollar bill is the maximum size needed). For example, if the value entered is 57.63 then the program should print the equivalent amount as:
2 twenty dollar bills
1 ten dollar bills
1 five dollar bills
2 one dollar bills
2 quarters
1 dimes
0 nickels
3 pennies

I will paste my code of what I have so far, I am using Eclipse.

package com.homework.assignment2;

import java.util.Scanner;

public class MoneyApp {

public static void main(String[] args) {
//Prompt for an amount between 1 & 1000
System.out.println("Enter in a dollar amount between \$1.00 & \$5,000.00:");

//get amount entered from user
Scanner sc = new Scanner(System.in);
double dollar = sc.nextDouble();
System.out.println("You typed = " + dollar + " thank you ");
//let's say I type in 3,333.99

//output amount

System.out.println("You typed =" + amount + "good job");

///Dollar Section

//Step 1

//take (original)3333.99 divide by 20

//Step 2 - to find out how much remains, take dollar only answer times 20

//166 x 20 = 3320
//take 3333 - 3320 to find out remaining amount. This leaves 13 dollars

//to find out how many tens, take 13 / 10, which gives 1.3
//to find out how much we have remaining, take 10 x 1

//take 13 - 10 = 3.
//take the remaining 3 divide 5, which equals 0 fives.
//0 x 5 = 0
//3 - 0 = 3

//3 / 1 = 3, number of 1's given.
------------------------------------------

//166 x 20 = 3320
//1 x 10 = 10
// 0 x 5 = 0
// 3 x 1 = 3
//total = 3333 (total)

///Change Section
//take 'original' which is 3333.99 subtract 3333.00 from it to equal .99 remaining

//remaining amount is still 3, next number is 3 divided by 1

}

}

**As you can see I spent quite some time just making comments to do the math in my head and get it on paper. I'm not quite sure how to turn all of this into workable code. Any assistance would be great. Thank you!

2. ## Re: Some java assistance

Convert the amound of money to pennies; that makes \$1 == 100 pennies etc. You can do integer arithmetic on that amount (hint: / and % are of help here).

kind regards,

His

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•