Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am working on a java homework problem. I have it done but when I compile and r

ID: 3670386 • Letter: I

Question

I am working on a java homework problem. I have it done but when I compile and run it, my dollar values in the return are correct but not my change amounts. The question is below and my answer is below that.

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

Here is what I have. This is chapter 2 homework so it has to be VERY basic...

import java.util.Scanner;
public class PP2_11{



public static void main(String[] args)

{
  
    double amount;
  
    int one, five, ten;
  
    int pennies, nickles, dimes, quarters;
    
    System.out.print("Enter Amount: ");
    Scanner scan=new Scanner(System.in);
  
    amount = scan.nextDouble();

    ten = (int) amount/10;
    amount = amount%10;
  
    five = (int) amount/5;
    amount = amount%5;

    amount/1;
    amount = amount%1;

    quarters = (int) (amount/0.25);
    amount = amount%25;

    dimes = (int) (amount/0.10);
    amount = amount%10;
  
    nickles = (int) (amount/0.05);
    amount = amount%5;
  
    pennies = (int) (amount/0.01);
    amount = amount%1;
  
    System.out.println(ten + "ten(s). ");
    System.out.println(five + "five(s). ");
    System.out.println(one + "one(s). ");
    System.out.println(quarters + "quarter(s). ");
    System.out.println(dimes + "dime(s). ");
    System.out.println(nickles + "nickle(s). ");
    System.out.println(pennies + "pennie(s). ");

Explanation / Answer

import java.util.Scanner;
public class Pennny{



public static void main(String[] args)

{

    double amount;

    int one, five, ten,twenty;

    int pennies, nickles, dimes, quarters;
   
    System.out.print("Enter Amount: ");
    Scanner scan=new Scanner(System.in);

    amount = scan.nextDouble();

    twenty = (int) (amount/20);
    amount = amount%20;

   
    ten = (int) (amount/10);
    amount = amount%10;

    five = (int) amount/5;
    amount = amount%5;

    amount/1;
    amount = amount%1;

    quarters = (int) (amount/0.25);
    amount = amount%0.25;

    dimes = (int) (amount/0.10);
    amount = amount%0.10;

    nickles = (int) (amount/0.05);
    amount = amount%0.05;

    pennies = (int) (amount/0.01);
    amount = amount%0.01;


    System.out.println(twenty + "twenty(s). ");
    System.out.println(ten + "ten(s). ");
    System.out.println(five + "five(s). ");
    System.out.println(one + "one(s). ");
    System.out.println(quarters + "quarter(s). ");
    System.out.println(dimes + "dime(s). ");
    System.out.println(nickles + "nickle(s). ");
    System.out.println(pennies + "pennie(s). ");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote