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
skelet666 [1.2K]
4 years ago
6

Write a program (Console or GUI) that determines the change to be dispensed from a vending machine. An item in the machine can c

ost between 25 cents and 1 dollar, in 5-cent increments (25, 30, 35,…,95, 100), and the machine accepts only a single dollar bill to pay for the item. For example, a possible sample dialog might be the following:
Output: Enter price of item (from 25 cents to a dollar, in 5-cent increments):

45 You bought an item for 45 cents and gave me a dollar, so your change is 2 quarters, 0 dimes, and

Computers and Technology
1 answer:
Stells [14]4 years ago
3 0

Answer:

Here is the JAVA program:

import java.util.Scanner;  //to accept input from user

public class Main {   //class name

  public static void main(String[] args) {  //start of main function

Scanner input =new Scanner(System.in);  // creates Scanner class object

int amount, quarters, dimes, nickels, pennies,change;   //declare variables

System.out.println("Enter the price of the(from 25 cents to a dollar, in 5-cent increments): ");  //prompts user to enter the price

amount=input.nextInt();   //reads amount from user

change= 100-amount;   //computes change

System.out.println("You bought an item for " + amount+" cents and gave me a dollar, so your change is :");  

quarters=change/25;  //computes quarters

change=change%25;  //computes quarter remaining

if(quarters == 1)   // if quarter is equal to 1

System.out.println(quarters+ " quarter");   //prints quarter value in singular

else if (quarters>1)   // if value of quarters is greater than 1

System.out.println(quarters+" quarters");     //prints plural quarters value

dimes=change/10;  //computes dimes

if(dimes == 1)   // if value of dime is equal to 1

System.out.println(dimes+ " dime");   //prints single value of dimes

else if (dimes>1)   //if value of dimes is greater than 1

System.out.println(dimes+" dimes");  //prints plural value of dimes

change=change%10;   //computes dimes remaining

nickels=change/5;  //computes nickels

if(nickels == 1)   //if value of nickels is equal to 1

System.out.println(nickels+ " nickel");   //prints single value of nickels

else if (nickels>1)   //if value of nickels is greater than 1

System.out.println(nickels+" nickels");   //prints plural value of nickels

change=change%5;    //computes nickels remaining

pennies=change;  //computes pennies

if(pennies == 1)   //if value of pennies is equal to 1

System.out.println(pennies+ " penny");   //prints single value of pennies

else if (pennies>1)    //if value of pennies is greater than 1

System.out.println(pennies+" pennies");     } }  //prints plural value of pennies

Explanation:

I will explain the program with an example:  

Suppose amount= 75  

Then change = 100 - amount= 100 - 75 = 25  

change = 25  

quarters = change/25 = 25/25 = 1  

quarters = 1  

change = change % 25 = 25%25 = 0  

dimes = 0/10 = 0  

Now all other values are 0.  

Now the following line is printed on screen:  

You bought an item for 75 cents and gave me a dollar. Your change is:  

Now program moves to if part  

if quarters == 1  

This is true because value of quarter is 1  

sot "quarter"   is displayed with the value of quarters

Now the following line is printed on screen:  

1 quarter  

So the complete output of the program is:  

You bought an item for 75 cents and gave me a dollar. Your change is:  

1 quarter

You might be interested in
Write a program to compute the sum of digits in a number given by the user. You must use your own function to compute the sum of
Sergio [31]

Answer:

python program compute the sum of digits of a number using function.....hope this answer is perfect and better for urr question....thanks

4 0
3 years ago
Select the correct answer from each drop-down menu.
DerKrebs [107]

Answer:

?

Explanation:

?!?!

3 0
3 years ago
In which career field, would the Computing Technology Industry Association's CompTIA A+ certification be useful?
Anna [14]
It's geared towards system administration but would also be useful for devops.
5 0
4 years ago
Among your selection in different online interfaces, which are your top three favorites?​
topjm [15]
What is this ? History or ?
6 0
3 years ago
Read 2 more answers
Plz help
vazorg [7]

The correct answer is:


a. All parts of the circuit will begin to carry higher amounts of current than normal.


Explanation:


When two or more than two conductors of different phases touch each other in a power line, the part of the impedance is shunted out of the circuit due to which a large current flow in the un-faulted phases, such current is called the short circuit current. Short circuit current decreases the impedance in the circuit while the current in the circuit increases.

8 0
3 years ago
Read 2 more answers
Other questions:
  • What operating system uses Fastboot?
    10·2 answers
  • The Distribute commands will evenly distribute the rows and columns within what? The width and height of the document. The width
    5·1 answer
  • What is the full path of the directory on this computer containing the SAM registry hive file
    15·1 answer
  • You learned about microcomputer a personal computer designed for use by an individual. Perform online research find out the diff
    12·1 answer
  • A #1 Phillips screwdriver has a shaft diameter of 
    13·1 answer
  • Is the following an example of social media viral marketing? Indicate your response by selecting Yes or No.
    7·1 answer
  • In 1988, Robert Morris, Jr. launched a program called the _________ that used weaknesses in e-mail programs and operating system
    5·1 answer
  • Which of the following sentences is correct?a. Arithmetic log unit is used to perform both integer and floating point computatio
    8·1 answer
  • Week 3 Discussion Requirements Modeling Requirements modeling is one of the earlier phases of software development where require
    7·2 answers
  • What is ICT?Write down the uses of ICT​
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!