Question: Write a program named Groceries that accepts input file items.txt the user. The data in the input file represents grocery items purchased along with their

Write a program named Groceries that accepts input file items.txt the user. The data in the input file represents grocery items purchased along with their price and their discount category. Your program should compute and print a double representing the total cost of the grocery items. Each item is represented by three tokens starting with the name of the item followed by its discount category ("red", "blue" or "none") followed by its full price. The discount category may include capitalization. The different discount options are: red: 10% off full price blue: 25% off full price none: full price For example, if the input file items.txt has the following text: Write a program named Groceries that accepts input file items.txt the user.

The program should print 9.59. Explanation: The avocado will cost $0.9 because a discount of 10% off of $1 is $0.1. Blueberries cost the full price of $5. Milk will cost $1.50 because it receives a discount of 25% off of $2.00. Cream will cost $0.9 and cereal will cost the full price of $1.29. The total is 0.9 + 5 + 1.5 + .9 + 1.29 = 9.59. Notice that the input may span multiple lines and may have different spacing between tokens. The entire file represents a single grocery bill. You may assume that the input file exists and has the format described above. The file will always contain at least one grocery item and will always contain a number of tokens that is a multiple of 3. The second token in every triple will always be one of "red", "blue" or "none".

avocado RED 1 blueberries none 5 milk blue 2.00 cream red 1.00 cereal None 1.29

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!