Results 1 to 2 of 2
  1. #1
    trtmerlin is offline Member
    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Default 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
    //answer is 166

    //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. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default 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
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. assistance w/ java programming assignment
    By clemsontigers in forum New To Java
    Replies: 4
    Last Post: 04-07-2011, 09:07 PM
  2. Java Generics assistance and confusion
    By sideswipe091976 in forum Advanced Java
    Replies: 9
    Last Post: 03-30-2011, 09:24 AM
  3. Learning Generics in Java. Need Assistance
    By codex in forum New To Java
    Replies: 1
    Last Post: 03-25-2011, 06:00 PM
  4. Looking for assistance
    By s_dawg101 in forum New To Java
    Replies: 32
    Last Post: 11-04-2009, 03:49 AM
  5. Java N00B - Remote Assistance Invitations
    By victimist in forum Java Applets
    Replies: 6
    Last Post: 10-25-2008, 02:30 AM

Posting Permissions

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