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]
3 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]3 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 if/else if statement is actually a form of the __________ if statement.
romanna [79]

Answer:

The answer to this question is "nested".

Explanation:

The answer to this question is nested because, In programming languages, there is a concept of nested if-else statement. In nested if-else statement placing if statement inside another IF Statement that is known as nested If in C Programming.

Example of nested if can be given as

#include <stdio.h>

int main()

{

  int a,b,c;

printf("Enter 3 number\n");

scanf("%d",&a);

scanf("%d",&b);

scanf("%d",&c);

   if(a>b)

   {

    if(a>c)

    {

        printf("A is greater: %d",a);

    }

   }

   else

   {

       if(b>c)

       {

           printf("B is greater: %d",b);

       }

       else

       {

           printf("C is greater: %d",c);  

       }

   }

   return 0;

}

output:

Enter 3 number  

4

7

9

c is greater: 9

8 0
3 years ago
In computing descriptive statistics from grouped data, a. data values are treated as if they occur at the midpoint of a class. b
koban [17]

Answer: Option A: data values are treated as if they occur at the midpoint of a class

Explanation: In computing descriptive statistics from grouped data, data values are treated as if they occur at the midpoint of a class

7 0
3 years ago
Read 2 more answers
Explain 5 documents that can<br>be created by using<br>ms word?​
arlik [135]
I don’t understand? What you mean by that
4 0
3 years ago
Read 2 more answers
Which generation of programming languages provides programmers with a visual environment for coding programs?
Andreyy89

5GL or the fifth-generation language is programming that uses a visual or graphical development interface to create source language that is usually compiled with a 3GL or 4GL language compiler.  Fifth Generation Programming or Visual programming language, is also known as natural language. It provides a visual or graphical interface, called a visual programming environment, for creating source codes.

6 0
3 years ago
Inserting diagrams into documents can help readers better understand document text. True or False?
Masja [62]
It's true because you can get a better understanding when looking at the evidence.
4 0
3 years ago
Other questions:
  • The first graphical browser application for using the web was netscape. <br> a. True <br> b. False
    8·1 answer
  • What type of organizational structure would you want to use for this company (by function, by process, by product, and so on)? E
    11·1 answer
  • Which feature is an interface between the user and the file system of a computer?
    6·2 answers
  • What kind of software consists of the programs that control or maintain the operations of a computer and its devices?
    11·1 answer
  • PLZ HELP ME! What is a false statement about online time?
    9·1 answer
  • You resurrected an old worksheet. It appears to contain most of the information that you need, but not all of it. Which step sho
    5·1 answer
  • The order of precedence is very important when building formulas in Excel. Which of the following formulas will produce 778 as t
    11·1 answer
  • Yan wants to attract customers specifically searching on Google for Time-B-Gone, his company's unique office-support product. Hi
    7·1 answer
  • The backbone networks of the Internet are typically owned by long-distance telephone companies called
    12·1 answer
  • 1. Keisha is in her first semester of college and is taking 10 credit hours: ACA 122, CIS 110, PSY 150, and developmental math.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!