1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Yanka [14]
2 years ago
11

9.18 LAB: Exact change - methods Write a program with total change amount as an integer input that outputs the change using the

fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and pennies. Use singular and plural coin names as appropriate, like 1 penny vs. 2 pennies. Ex: If the input is:
Computers and Technology
1 answer:
Sedbober [7]2 years ago
6 0

Answer:

Explanation:

The following code is written in Java. It asks the user to enter the amount of change needed. This is done as a double since we are dealing with coins and not full dollar values alone. It then makes the necessary calculations to calculate the number of each coin needed and outputs it back to the user. A test case has been provided in the picture below with a sample output.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       int dollars = 1;

       double quarters = 0.25;

       double dimes = 0.10;

       double nickels = 0.05;

       double pennies = 0.01;

       Scanner in = new Scanner(System.in);

       System.out.println("Enter Change Value: ");

       double change = in.nextDouble();

       int numDollars, numQuarters, numDimes, numNickels, numPennies;

       double newChange;

       numDollars = (int) (change / dollars);

       newChange = change % dollars;

       numQuarters = (int) (newChange / quarters);

       newChange = newChange % quarters;

       numDimes = (int) (newChange / dimes);

       newChange = newChange % dimes;

       numNickels = (int) (newChange / nickels);

       newChange = newChange % nickels + 0.001;

       numPennies = (int) (newChange / pennies);

       newChange = newChange % pennies;

       

       System.out.println("Minimum Num of Coins needed: ");

       if (numDollars != 1) {

           System.out.println(numDollars + " Dollars");

       } else {

           System.out.println(numDollars + " Dollar");

       }

       if (numQuarters != 1) {

           System.out.println(numQuarters + " Quarters");

       } else {

           System.out.println(numQuarters + " Quarter");

       }

       if (numDimes != 1) {

           System.out.println(numDimes + " Dimes");

       } else {

           System.out.println(numDimes + " Dime");

       }

       if (numNickels != 1) {

           System.out.println(numNickels + " Nickels");

       } else {

           System.out.println(numNickels + " Nickel");

       }

       if (numPennies != 1) {

           System.out.println(numPennies + " Pennies");

       } else {

           System.out.println(numPennies + " Penny");

       }

   }

}

You might be interested in
The main part of your program has the following line of code.
Arlecino [84]

Answer: D

Explanation:

It is not A or C because the "d" in "Divide" is capitalized and the d is lowercase in calling the function. Therefore the answer is D (the last choice) because numA / numB (30 / 5) equals 6.

5 0
3 years ago
I want to sign up for brainly but it won't let me. It keeps saying "we can complete your registration at this time".
vekshin1
Try reinstalling the app or check if your wifi connection is good, if everything’s good but the app still doesn’t work then just use the website
5 0
3 years ago
which of the following indicates that the loop should stop when the value in the quantity variable is less than the number 50​
yan [13]

Answer:

while (quantity >= 50)

Explanation:

Required

Stop when quantity is less than 50

To do this, we make use of a while statement and the syntax is:

while (condition){ }

If the loop should stop when quantity is less than 50; then it means the loop would continue when quantity is greater or equal to 50

So, we have:

while (quantity >= 50)

6 0
2 years ago
Name two ways you can identify the pid number of the login shell.
Katyanochek1 [597]
Two approaches are:
Echo $$
Ps
3 0
3 years ago
What is Identity Theft?
olga55 [171]
A is correct! We did this in Law!

Have a merry Christmas!
5 0
3 years ago
Other questions:
  • Questions 6 - 9 Refer to the following code: public class WhatsIt { private int[] values; private double average; public WhatsIt
    7·1 answer
  • A ________ is a member function that is automatically called when a class object is
    6·1 answer
  • When mapping a drive, you can type in the path to the shared folder on the host computer. what is the syntax for the path?
    7·1 answer
  • . Explain and demonstrate the functionality of timer devices in an embedded system[
    9·1 answer
  • Which elements of a myth appear in this story from early babylon
    14·1 answer
  • For each part create a vector n in which the first element is 1, the increment is 1 and the last term is 5, 50, or 5,000. Then u
    13·1 answer
  • Why is it NOT a good practice to save everything on the desktop?
    6·2 answers
  • In this exercise, you will get some practice with the __add__ method by implementing it for a class called ContactBook. This cla
    12·1 answer
  • If you are worried that team members will not keep sensitive information private, you could ask them to sign a ________ agreemen
    15·1 answer
  • Which of the following best explains how algorithms that run on a computer can be used to solve problems?
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!