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
One item you will NOT need to provide when opening up a bank account
gladu [14]

Answer:

You don't need a birth certificate

Explanation:

8 0
3 years ago
Read 2 more answers
You've been asked to design a soho network on a work place. the other offices in the building also have wireless networks. while
Kipish [7]

In the scenario in which you should to design a SOHO network on a work place. the other offices in the building also have wireless networks. while setting up a wireless network for the SOHO, your initial step should be to run a wireless site survey.

This survey will help you to know which access points (AP) are in the most optimal locations.

5 0
3 years ago
In older systems, often the user interface mainly consisted of ____-control screens that allowed a user to send commands to the
Scilla [17]

Answer:

Process

Explanation:

In older systems, the user interface mainly consisted of process-control screens that allowed a user to send commands to the system. These systems were used in a great variety of industries, and it gave the user control over process measurements or process variables. It also allowed the user to view the current state of the process, modify the operation of the process, and perform other related actions.

6 0
4 years ago
Chef is an orchestration tool?<br> Yes or No
nlexa [21]
I believe its yes. you can just look it up 

5 0
4 years ago
Read 2 more answers
A website must have a unique address with all the following features
7nadin3 [17]

Answer:

Considering it's just the 'Address' as in the weblink the weblink doesn't need Option E -

Explanation:

5 0
3 years ago
Other questions:
  • A species of snake lives in a rainforest. Which would be an adaptation for this
    10·2 answers
  • An employee who interacts with customers regarding the nature of their car problems, rather than actually working on the vehicle
    12·2 answers
  • Write a program that finds the largest in a series of numbers entered by the user.The program must prompt the user to enter numb
    12·1 answer
  • State and derive the law of conservation of energy​?
    8·2 answers
  • Determine whether the phrase below is a sentence or a fragment.
    12·1 answer
  • What is one difference between IDLE and Eclipse?
    7·2 answers
  • The one who will defeat me in this typing race I will mark the one brainliest:
    5·2 answers
  • Write the Flowchart to find Even number between 1 to 50<br>​
    9·1 answer
  • Python code for converting between minutes to seconds. For example 5 minutes= 300 seconds. please help me with this
    7·1 answer
  • Cutting edge technoligies of Cisco​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!