answer.
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
statuscvo [17]
2 years ago
11

Write a program that simulates the functionality of a vending machine having the following characteristics:• The vending machine

offers 5 products• The vending machine accepts coins, 1 dollar bills, and 5 dollar bills• The change is always given in coins, with maximum possible number of coins in each value: 25, 10, 5 or 1 cent.• The selections available for user are numbers from 1 to 5.• The user enters the money – simulate the action through a loop that ends when the user enters 0. Each coin, or paper bill will be read individually.• The user makes the selection, and the machine allows a maximum 4 other selections if the amount entered doesn’t cover the price of the item.• Once an item is delivered, the machine gives the change in coins.• There is no increment for the money during one selection.• The user can stop the selection at any time by entering 0 for the product selection.• If the user chooses to cancel the selection, the machine returns the initial amount in coins.• Display the outcome of the operation for each alternative you consider possible for the vending machine.• Make sure that the machine returns the correct change at all times.
Computers and Technology
1 answer:
ValentinkaMS [17]2 years ago
5 0

Answer:

Check the explanation

Explanation:

import java.util.*;

public class VendingMachineAssignement {

   public static void main(String[] args) {

       Scanner keyboard = new Scanner(System.in);

       double item1 = 1.25;

       double item2 = .75;

       double item3 = .90;

       double item4 = .75;

       double item5 = 1.50;

       double item6 = .75;

       System.out.print("Enter an item number: ");

       int item = keyboard.nextInt();

       System.out.print("Enter the amount paid: ");

       double paid = keyboard.nextDouble();

       if (item == 2 || item == 4 || item == 6)

       {

           if (paid >= item2)

           {

               System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item2) + ". Please come again!");

           }

           if (paid < item2)

           {

               System.out.println("Please insert another " + "$" + (item2-paid));

           }

       }

       else if (item == 1)

       {

           if (paid >= item1)

           {

               System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item1) + ". Please come again!");

           }

           if (paid < item1)

           {

               System.out.println("Please insert another " + "$" + (item1-paid));

           }

       }

       else if (item == 3)

       {

           if (paid >= item3)

           {

               System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item3) + ". Please come again!");

           }

           if (paid < item3)

           {

               System.out.println("Please insert another " + "$" + (item3-paid));

           }

       }

       else if (item == 5)

       {

           if (paid >= item5)

           {

               System.out.println("Thank you for buying item " + item + ", your change is $" + (paid-item5) + ". Please come again!");

           }

           if (paid < item5)

           {

               System.out.println("Please insert another " + "$" + (item5-paid));

           }

       }

   }

}

You might be interested in
The Spinning Jenny reduced the number of workers necessary to _______. a.remove cotton seeds from fibers b.pump water from the m
bazaltina [42]

The answer is D: Turn yarn into cloth.

During the industrial revolution, a number of new inventions in the textile industry greatly impacted this industry. However, it was the invention of the Spinning Jenny that is credited a lot. It helped move the textile industry from homes to factories and made wool spinning easier and faster. This invention, however, impacted the labor workforce. It reduced the amount of work needed to produce yarn. One worker was able to work 8 or more spools at once and rose to 120 due to technological advancements.

5 0
2 years ago
Return 1 if ptr points to an element within the specified intArray, 0 otherwise.
Paladinen [302]

Answer:

int withinArray(int * intArray, int size, int * ptr) {

      if(ptr == NULL) // if ptr == NULL return 0

            return 0;

      // if end of intArr is reached

      if(size == 0)

          return 0; // element not found

  else  

          {

            if(*(intArray+size-1) == *(ptr)) // check if (size-1)th element is equal to ptr

                   return 1; // return 1

            return withinArray(intArray, size-1,ptr); // recursively call the function with size-1 elements

         }

}

Explanation:

Above is the completion of the program.

4 0
2 years ago
Compare the memory organization schemes of contiguous memory allocation and paging with respect to the following issues: a. Exte
Free_Kalibri [48]

Answer:

The comparison is based on memory organization schemes of contiguous memory allocation and paging with respect to External fragmentation, Internal fragmentation and Ability to share code across processes.

Explanation:

Memory organization schemes of contiguous memory allocation:

Contiguous memory allocation schemes suffers from external fragmentation. The reason is that address space is distributed contiguously and the holes and gaps keep growing when the old processes die and new processes are introduced. The variable size partition suffers from external fragmentation however the fixed size partitions do not suffer from external fragmentation. Contiguous memory allocation with variable size partitions does not encounter an internal fragmentation but with fixed size partitions suffers from internal fragmentation. Contiguous memory allocation does not support sharing code across processes. This is because the virtual memory segment of a process is not fragmented into non-contiguous fine grained blocks.

Paging:

Paging does not encounter external fragmentation as pages are of the fixed or equal size. So this reduces external fragmentation. However paging suffers from internal fragmentation. This is because a process can request more space or it can request for a less space. When page is allocated to the such a process that page is no longer utilized.This results in internal fragmentation because of the wastage of space even when the page has internal space but cannot be fully utilized. Paging allows to share code across processes.

5 0
2 years ago
HackerCards is a trendy new card game. Each type of HackerCard has a distinct ID number greater than or equal to 1, and the cost
joja [24]

Answer:

I don't know if this is right output is {1,3}

Explanation:

5 0
2 years ago
A Color class has three public, integer-returning accessor methods: getRed, getGreen, and getBlue, and three protected, void-ret
jek_recluse [69]

Answer:

The following code are:

public void dissolve() {

setRed(getRed()+1);

setGreen(getGreen()+1);

setBlue(getBlue()+1);

alpha+=1;

}

Explanation:

Here, we define the void type function "dissolve()" inside it, we set three function i.e, "setRed()", "setGreen()", "setBlue()" and then we increment the variable "alpha" by 1.

Inside those three mutators method we set three accessor methods i.e, "getRed()", "getGreen()" , "getBlue()" and increment these accessor by 1.

The values will not be returned by the mutator functions, the accessor will be returned the values.

6 0
2 years ago
Other questions:
  • A storyboard is essentially an outline of a web page's content and design<br> -True or False
    8·2 answers
  • Your computer has a quad-core processor that supports multithreading installed. given that the system is running windows, how ca
    6·1 answer
  • Zander is beginning to take college courses to prepare for a career in computer science, which is the study of using logic to cr
    5·1 answer
  • #Create a class called Name. Name should have two attributes
    11·1 answer
  • Write multiple if statements. If car_year is 1969 or earlier, print "Few safety features." If 1970 or later, print "Probably has
    12·1 answer
  • Ken Olson, president of Digital Equipment Corp. in the late 1970's, Thomas J. Watson, chairman of IBM in the early 1940's, and T
    6·1 answer
  • A form of artificial intelligence that can perform many complex, _______ tasks. Select one: a. serialized b. repetitive c. non-r
    7·1 answer
  • E-mail is an efficient means of disseminating information quickly and inexpensively. However, HIPAA regulations affect e-mail us
    13·1 answer
  • (a) Show how to use (the Boolean formula satisfiability program) satisfiable num (and substitute) to find a satisfying assignmen
    9·1 answer
  • It is also called teleconferencing or web conferencing,which is an online meeting wherein two or more people can see,hear,and ta
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!