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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
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
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning