Write a program that reads a monetary amount in dollars and cents (such as 37.84) and computes the equivalent in bills and coins, using the largest denominations possible.

Use a Scanner object to read in a double value for the monetary amount
Convert the total monetary amount to an integer representing the total number of cents (there are 100 cents in a dollar)
US monetary denominations
ten dollar bill = 1000 cents
five dollar bill = 500 cents
one dollar bill = 100 cents
quarter coin = 25 cents
dime coin = 10 cents
nickel coin = 5 cents
penny coin = 1 cent
Use integer division (/) and modulus (%) to calculate each denomination and the cents left over
Hint: You will need to successively divide the remaining cents by the number of cents in the denomination, starting with the ten dollar bills.
tens = remainingCents / 1000; // Divide the total cents by the number of cents in $10
remainingCents = remainingCents % 1000; //Remainder of division by 1000 is what is left after $10 bills taken out
When user input appears as shown in Figure 1, your program should produce output as shown in Figure 2.

Figure 1: (input)

37.84
Figure 2: (output)

$37.84 is equivalent to the following:
3 ten dollar bills
1 five dollar bills
2 one dollar bills
3 quarters
0 dimes
1 nickels
4 pennies


import java.util.Scanner;

public class MoneyConversion
{
// This program reads a monetary amount and computes the equivalent in bills and coins
public static void main (String[] args)
{
double total;
int tens, fives, ones, quarters, dimes, nickels;
int remainingCents;

Scanner scnr = new Scanner(System.in);

// Read in the monetary amount
total = scnr.nextDouble();

// Add the remaining code to finish out the program

}
}

Respuesta :

Using the knowledge of computational language in python we can write the code as program that reads a monetary amount in dollars and cents (such as 37.84) and computes the equivalent in bills and coins, using the largest denominations possible.

Writting the code:

import java.util.Scanner;

public class Money {

public static void main(String[] args) {

double amount; // This displays user's amount

int one, five, ten;

int penny, nickel, dime, quarter;

// Create a Scanner object to read input.

Scanner kb = new Scanner(System.in);

// Get the user's amount

System.out.print("What is the amount? ");

amount = kb.nextDouble();

// Calculations

ten = (int) (amount / 10);

amount = amount % 10;

five = (int) (amount / 5);

amount = amount % 5;

one = (int) (amount / 1);

amount = amount % 1;

quarter = (int) (amount / .25);

amount = amount % .25;

dime = (int) (amount / .10);

amount = amount % .10;

nickel = (int) (amount / .05);

amount = amount % .05;

penny = (int) (amount / .01);

amount = amount % .01;

// Display the results

//println adds a new line by default

System.out.println(ten + " tens.");

System.out.println(five + " fives.");

System.out.println(one + " ones.");

System.out.println(quarter + " quarters.");

System.out.println(dime + " dimes.");

System.out.println(nickel + " nickels.");

System.out.println(penny + " pennies.");

}

}

See more about JAVA at brainly.com/question/12975450

#SPJ1

Ver imagen lhmarianateixeira