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
Your college has several campuses located across the city. within each campus, the buildings are interconnected with a campus ar
iris [78.8K]

Answer:

Metropolitan Area Network (MAN)

Explanation:

8 0
2 years ago
If you are working with a team of students on a class project and your team chooses to share content by uploading Word and Excel
shepuryov [24]

Answer:

The answer is  "Minimal".

Explanation:

The limited teamwork tools are also known as a collaboration with a team of students on a joint assignment, and the team prefers to exchange information by exporting Word and Excel files to a file server. It provides a framework for teamwork, that allows people to work together.  

  • It is also known as a method, that target at helping a community of two or more individuals to accomplish a shared purpose or objective.  
  • This tool may be non-technological, such as paper, flip charts, post-it notes or whiteboards, other choices were incorrect, because they do not define the given scenario.
5 0
3 years ago
A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the va
Andrej [43]

Answer:

  1. def cube(num):
  2.    return num * num * num  
  3. result = cube(4)

Explanation:

Given the function <em>cube()</em> as in Line 1 - 2.

To pass the value 4 to this function, we just place 4 inside the parenthesis of the function (Line 4). The value of 4 will be multiplied by itself for two times and the final multiplied result (4 * 4 * 4 = 64) will be returned to variable result.

If we use <em>print() </em>function to display the result, we shall see a value of 64 printed on the terminal.

7 0
3 years ago
Which is a primary document?<br> a. letter<br> b. dictionary<br> c. textbook<br> d. website
just olya [345]
Its B because a primary document means something with a <span>source or evidence</span> that gives u a lot of information.
6 0
3 years ago
What internal commands can we use when in interactive mode? can we use CLS and CD?
krok68 [10]
The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
3 0
3 years ago
Other questions:
  • You are researching RAM for a computer you are building for a friend who will be using the system as a home office server for he
    6·1 answer
  • Given an integer variable bridgeplayers, write an statement that increases the value of that variable by 4.
    9·1 answer
  • A type of specialty processor devoted exclusively to protecting your privacy.
    9·2 answers
  • Garrett has a column of data. What can he do at the bottom of that column of data using an Auto function? Check all that apply.
    8·2 answers
  • While waiting to be seated at a restaurant, Jason receives a customer loyalty coupon through an app on his mobile phone for half
    7·1 answer
  • You don't have policies that force settings for the look of users' computer desktops. Each user's chosen desktop settings are ap
    15·2 answers
  • WHAT TYPES OF ACTIVITIES ARE PERFORMED BY HEALTH CARE SOFTWARES
    8·1 answer
  • A mobile operating system is stored on a ___ chip.​
    11·1 answer
  • Can anyone fix this code for me?
    8·1 answer
  • If you’d like to have multiple italicized words in your document, how would you change the font of each of these words
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!