Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating a python program that displays a receipt for a purchase: The Item Class First design and implement an items class. Instantiate it to create

Creating a python program that displays a receipt for a purchase:

The Item Class

First design and implement an items class. Instantiate it to create the item objects that are part of the receipt.

The item class should have three attributes.

__name - A string with the item name.

__price - A float with the item price in dollars.

__taxable - A boolean that is true if the item is taxed.

The item class should have the following methods.

__init__ - The constructor.

__str__ - returns the item as a string.

getPrice - return the price of the item.

getTax - Takes the tax rate as a parameter. Returns the tax charged on the item.

The Receipt Class

Next, design and implement a Receipt class.

The receipt class should have two attributes.

__tax_rate - The tax rate in this area.

__purchases - A list of items.

The Receipt class should have the following methods.

__init__ - The constructor. Takes the tax rate.

__str__ - returns the full receipt as a string.

addItem - adds a new item to the receipt.

Programming

Implement a program, that asks the users for items. For each item, read in the name, price, and if the item is taxable. When the user says that do not want to add any more items, print out the full receipt.

The receipt must have the following contents:

Each item listed with its price.

The total cost of the items.

The total tax charged on all items.

The grand total with tax added.

The current date when the receipt we generated.

All values must be shown to two decimal places.

EXAMPLE OUTPUT

Welcome to Receipt Creator

Enter Item name: Hot Dog

Enter Item Price: 5.15

Is the item taxable (yes/no): no

Add another item (yes/no): yes

Enter Item name: Soda

Enter Item Price: 2.50

Is the item taxable (yes/no): yes

Add another item (yes/no): yes

Enter Item name: Pretzel

Enter Item Price: 0.50

Is the item taxable (yes/no): no

Add another item (yes/no): yes

Enter Item name: Candy Bar

Enter Item Price: 1.25

Is the item taxable (yes/no): yes

Add another item (yes/no): no

----- Receipt 2018-01-02 16:21:49.515170 -----

Hot Dog_____________________________5.15

Soda________________________________2.50

Pretzel_____________________________0.50

Candy Bar___________________________1.25

Sub Total___________________________9.40

Tax_________________________________0.26

Total_______________________________9.66

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

2. Identify the purpose of your speech

Answered: 1 week ago