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
Levart [38]
3 years ago
11

Develop a program working as a soda vending machine. The program should show the product menu with price and take user input for

product number, quantity and pay amount. The output should show the total sale price including tax and the change. Organize the program with 4 functions and call them in main() based on the requirements.
Computers and Technology
1 answer:
Kipish [7]3 years ago
8 0

Answer:

Explanation:

The following vending machine program is written in Python. It creates various functions to checkItems, check cash, check stock, calculate refund etc. It calls all the necessary functions inside the main() function. The output can be seen in the attached picture below.

class Item:

   def __init__(self, name, price, stock):

       self.name = name

       self.price = price

       self.stock = stock

   def updateStock(self, stock):

       self.stock = stock

   def buyFromStock(self):

       if self.stock == 0:

           # raise not item exception

           pass

       self.stock -= 1

class VendingMachine:

   def __init__(self):

       self.amount = 0

       self.items = []

   def addItem(self, item):

       self.items.append(item)

   def showItems(self):

       print('Items in Vending Machine \n----------------')

       for item in self.items:

           if item.stock == 0:

               self.items.remove(item)

       for item in self.items:

           print(item.name, item.price)

       print('----------------\n')

   def addCash(self, money):

       self.amount = self.amount + money

   def buyItem(self, item):

       if self.amount < item.price:

           print('You can\'t but this item. Insert more coins.')

       else:

           self.amount -= item.price

           item.buyFromStock()

           print('You chose ' +item.name)

           print('Cash remaining: ' + str(self.amount))

   def containsItem(self, wanted):

       ret = False

       for item in self.items:

           if item.name == wanted:

               ret = True

               break

       return ret

   def getItem(self, wanted):

       ret = None

       for item in self.items:

           if item.name == wanted:

               ret = item

               break

       return ret

   def insertAmountForItem(self, item):

       price = item.price

       while self.amount < price:

               self.amount = self.amount + float(input('insert ' + str(price - self.amount) + ': '))

   def calcRefund(self):

       if self.amount > 0:

           print(self.amount + " refunded.")

           self.amount = 0

       print('Thank you!\n')

def main():

   machine = VendingMachine()

   item1 = Item('Kit Kat',  1.5,  2)

   item2 = Item('Potato Chips', 1.75,  1)

   item3 = Item('Snickers',  2.0,  3)

   item4 = Item('Gum',  0.50, 1)

   item5 = Item('Doritos',0.75,  3)

   machine.addItem(item1)

   machine.addItem(item2)

   machine.addItem(item3)

   machine.addItem(item4)

   machine.addItem(item5)

   print('Welcome!\n----------------')

   continueBuying = True

   while continueBuying == True:

       machine.showItems()

       selected = input('select item: ')

       if machine.containsItem(selected):

           item = machine.getItem(selected)

           machine.insertAmountForItem(item)

           machine.buyItem(item)

           a = input('buy something else? (y/n): ')

           if a == 'n':

               continueBuying = False

               machine.calcRefund()

           else:

               continue

       else:

           print('Item not available. Select another item.')

           continue

if __name__ == "__main__":

   main()

You might be interested in
Which studio produced the film the jazz singer the first of many talkies
sasho [114]
What is a talkie ? please tell me
7 0
3 years ago
Please answer ASAP!!!!!!
Blababa [14]

Answer:

the first constructor invocation will work.

pet temp("mouse", 5.99);

Explanation:

This will create a pet object on the stack, using the constructor.

If you want to create an object on the heap, you would use the new operator:

pet* pTemp = new pet("mouse", 5.99);

3 0
3 years ago
A bit pattern is shown below.<br> 01001110<br> Convert the bit pattern into decimal
Vera_Pavlovna [14]

Answer:

78

Explanation:

I always convert to hexadecimal first:

0100 = 4

1110 = E

(the matching of groups of 4 bits to one hex char is a lookup you can memorize)

so we have 4E, which is 4*16+14 = 78

Of course you can also go the long route:

01001110 = 0·2⁷+1·2⁶+0·2⁵+0·2⁴+1·2³+1·2²+1·2¹+0·2⁰ = 78

5 0
3 years ago
How do you whitelist or turn off ad blocker for brainly?
sweet-ann [11.9K]

Answer:

rightclick and it should give you the option

Explanation:

sddas

6 0
3 years ago
Read 2 more answers
Fill in the blank. The process that a wireless router uses to translate a private IP address on internal traffic to a routable a
AleksandrR [38]

Answer:

Network Address Translation (NAT)

Explanation:

With the aid of Network address translation(NAT), the IP addresses of a particular local network are translated or mapped into a single or multiple global or public IP addresses. Therefore, a wireless router could use NAT to translate its private IP address on internal traffic (network) to a routable address for the internet.

With NAT, businesses can use many internal IP addresses since they are just for internal purposes and will be eventually converted into a single or a few multiple routable IP addresses.

Three types of NAT are possible:

(i) Static NAT : There is a one - to - one mapping between private IP addresses and routable (public) IP addresses. One private IP is mapped to one public IP address.

(ii) Dynamic NAT : There is a many- to - many mapping between private IP addresses and routable (public) IP addresses. Multiple private IPs are mapped to many public IP addresses.

(iii) Port Address Translation (PAT) : Many - to - one relationship between the private IP addresses and public addresses. Many private IP addresses can be mapped or translated into a single public IP address. This type of NAT is also called NAT overload.

6 0
3 years ago
Other questions:
  • Is it bad to leave a co2 cartridge in an airsoft pistol?
    6·2 answers
  • In the ____, or ad hoc, layouts configuration, there is no access point at the center of a cell.
    7·1 answer
  • PLEASE HELP
    9·2 answers
  • Enumeration is defined as the process of extracting user names, machine names, network resources, shares, and services from a sy
    13·1 answer
  • Gina is upgrading your computer with a new processor. She installs the processor into your motherboard and adds the cooling syst
    13·2 answers
  • A technician is troubleshooting an employee laptop that has a wired network connectivity issue. The laptop can connect to the in
    9·2 answers
  • A PenTester has successfully exploited a remote host on a clients’ network. They want to create a backdoor on the host for futur
    11·1 answer
  • Write fade in shorthand​
    11·1 answer
  • Can you help me to write a code with functions,arrays,and pointers in c++?
    5·1 answer
  • Write a c program that asks the user to enter two numbers. the program should use the conditional operator to determine which nu
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!