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
Comments can be compared to a virtual _____.
Vladimir79 [104]
What's the rest of the question? Like A - B - C - D?
3 0
3 years ago
Which of the following is the best subject line for an e-mail sent to co-workers about rescheduling a team meeting?
Ilya [14]
Reschedule the team meeting <span />
6 0
2 years ago
Can someone tell me how to mark people the brainiest on a laptop?
Crazy boy [7]

When two people give answer to your question, then below their answer you will get a option Mark as Brainliest. You simply need to click that button

7 0
2 years ago
Jim is creating a form with validation. What are the two validation modes available to him?
Charra [1.4K]
Basic validation
Data validation
6 0
2 years ago
Explain the RISC and CISC architecture. Comparison of RISC and CISC in detail.
puteri [66]

Answer:RISC(reduced instruction set computer) is the computer used for low level operation by simple command splited into numerous instructions in single clock only and CISC(Complex instruction set computer) is the computer that performs the operation in single instruction.

RISC architecture has hardwired control unit,data cache unit,data path ,instruction cache and main memory as components .CISC architecture persist of  control unit,micro program control memory, cache, instruction and data path and main memory.

The differences between RISC and CISC are as follows:-

  • The instruction in RISC are less and and low complexes while CISC has several number of complex instruction.
  • The calculation done by RISC are precise and quick whereas CISC has slightly slow calculation processing.
  • The execution of RISC is faster as compared to CISC.
  • RISC uses hardware component for implementation of instruction because it does not persist its own memory and CISC implements instructions using its own memory unit .

6 0
3 years ago
Other questions:
  • Explain why testing can only detect the presence of errors, not their absence.
    14·1 answer
  • Computer virus is a<br> a. software<br> b. hardware<br> c. bacteria<br> d. none of these
    13·1 answer
  • Which of the following statements best deceive the relationship between carrying capacity and population size
    12·1 answer
  • What is the purpose of exporting your public key to the directory services server?
    11·1 answer
  • An investor is considering in which of two start-up companies to invest. The investor has faith in the industrial organization (
    9·2 answers
  • MICR is an input or output devices
    5·1 answer
  • Given the char * variables name1, name2, and name3, write a fragment of code that assigns the largest value to the variable max
    15·1 answer
  • Writing a function that implements a loop to collect a set amount of data. The function should use the serial object, the record
    9·1 answer
  • When text is used as a Hyperlink, it is usually underlined and appears as a different color.
    11·1 answer
  • true or false hardware diagnostics let you run a quick check of system hardware and can verify that most systems components are
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!