Create a class that models a store. You store has some number of products, for example cookies, chips, soda, and coffee (you get to decided how many products you have). Each product has a price and a stock (that is, how many products you have in the shelf). To modify this object create functions that: model someone making a purchase, where a purchase is composed of a list of items and the quantity to buy. The function should return the total amount to pay and should update the stock of the products. (As a sugestion (and added challenge) you can model the purchase as a class).S model a resupply truck that comes to restock your store

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I need help creating a class on python of a store. Above is an example of a car class. and the bottom what I got so far for the store class.

Car Class

Create a class that represents a car. This car object has a brand, a model, a year, mileage, available gas, and a gas efficiency constant. To modify this object create functions that:

  • checks if the car can travel a given distance
    • if the car has 4 gallons and an efficiency of 4 miles per gallon, can it travel 10 miles?
  • increases the mileage by an amount
  • updates the consumed fuel by a given mileage
    • if I have 10 gallons, an efficiency of 5 miles per gallon, and I traveles 3 miles, how many gallons do I have left?
class Car:

def__init__(self, brand, model, year, mileage, gasInTank, gasEfficiency):
self.brand = brand
self.model = model
self.year = year
self.mileage = mileage
self.gasInTank = gasInTank
self.gasEfficiency = gasEfficiency

defisThereEnoughGas(self, milesToTravel):
maxNoMiles = self.gasInTank * self.gasEfficiency

if milesToTravel > maxNoMiles:
returnFalse
else:
returnTrue

defincreaseMileage(self, miles):
self.mileage = self.mileage + miles

defupdateGasinTank(self, milesTraveled):
gasConsumed = milesTraveled * 1/self.gasEfficiency
self.gasInTank = self.gasInTank - gasConsumed
 
deftravel(self,milesToTravel):
ifself.isThereEnoughGas(milesToTravel):
self.increaseMileage(milesToTravel)
self.updateGasinTank(milesToTravel)
else:
print('There is not enought has in the tank to make this travel')

deftravelUgly(self,milesToTravel):
maxNoMiles = self.gasInTank * self.gasEfficiency
if milesToTravel > maxNoMiles:
print('There is not enough gas in the tank to make this travel')
 
else:
self.mileage = self.mileage + milesToTravel
gasConsumed = milesToTravel * 1/self.gasEfficiency
self.gasInTank = self.gasInTank - gasConsumed


# TEST DRIVEN DEVELOPMENT
myCar = Car('Nissan','Rogue',2015,1000,40,12)

'''
TEST 1

With 40 gallons in the tank and 12 miles per gallon, the max miles that can be traveled is 40*12 =480
'''
#output should be True
print('Can my car tavel 100 miles?',myCar.isThereEnoughGas(100))

# output should be False
print('Can my car tavel 100 miles?',myCar.isThereEnoughGas(600))

'''
TEST 2
'''

print('Current mileage:',myCar.mileage)
myCar.increaseMileage(100)
# the result should be 100 more
print('New mileage:',myCar.mileage)

'''
TEST 3
If I travel 24 miles I should have consumed 2 gallons of gas
'''
print('Gas in tank before travel:',myCar.gasInTank)
myCar.updateGasinTank(24)
# the result should be 24 less
print('Gas in tank after travel:',myCar.gasInTank)

'''
TEST 4
'''
print('--------------------------------------------')
myCar = Car('Nissan','Sentra',2015,1000,40,12)

print('Mileage before travel:',myCar.mileage)
print('Gas in tank before travel:',myCar.gasInTank)
myCar.travel(200)
print('Mileage after travel:',myCar.mileage)
print('Gas in tank after travel:',myCar.gasInTank)

'''
TEST 5
'''
print('--------------------------------------------')
myCar = Car('Nissan','Sentra',2015,1000,40,12)

print('Mileage before travel:',myCar.mileage)
print('Gas in tank before travel:',myCar.gasInTank)
myCar.travelUgly(200)
print('Mileage after travel:',myCar.mileage)
print('Gas in tank after travel:',myCar.gasInTank)
 
output:
Can my car tavel 100 miles? True
Can my car tavel 100 miles? False
Current mileage: 1000
New mileage: 1100
Gas in tank before travel: 40
Gas in tank after travel: 38.0
--------------------------------------------
Mileage before travel: 1000
Gas in tank before travel: 40
Mileage after travel: 1200
Gas in tank after travel: 23.333333333333332
--------------------------------------------
Mileage before travel: 1000
Gas in tank before travel: 40
Mileage after travel: 1200
Gas in tank after travel: 23.333333333333332
 
NEED HELP HERE:

Store Class

Create a class that models a store. You store has some number of products, for example cookies, chips, soda, and coffee (you get to decided how many products you have). Each product has a price and a stock (that is, how many products you have in the shelf). To modify this object create functions that:

  • model someone making a purchase, where a purchase is composed of a list of items and the quantity to buy. The function should return the total amount to pay and should update the stock of the products. (As a sugestion (and added challenge) you can model the purchase as a class).S
  • model a resupply truck that comes to restock your store

WHAT I GOT SO FAR

class Store:

def__int__ (store, milk, cookies, books, coleslaw, staples, blue_paint, franklin_badge, wallet, vcr, eraser):
store.milk = 7
store.cookies = 8
store.books = 12
store.coleslaw = 5
store.staples = 15
store.blue_paint = 30
store.franklin_badge = 2000
store.wallet = 8
store.vcr = 100
store.eraser = 2

defstoreStock(self, )
 



print('Welcome to the store, please purchase from our great inventory of 10 items')
Expert Solution
Note :

1. Because we only get 2:30 hours to solve, I am unable to explain the code but I have added the comments in code.

    These comments will help you to understand the code and its logic.

2. As mentioned, code is about Store class.

3. To save time I have only used cookies, chips, soda, and coffee. You can easily add others by using the copy-paste                mechanism.

4. Output screenshots explanation:

A: If stocks are already full, according to that message will get printed.

B: Shows updated stock and our total price.

C: Shows message if we try to purchase out of the stock product.

D: Shows message if we try to give a negative value.

E: Shows invoice.

F: Shows that even if you try to purchase again then stocks are not updated because we haven't refilled our stocks.

    At the same time, our invoice gets reset to 0.

G: Shows stocks get reset after refilling the stocks.

 

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education