Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The goal of this part is to write a class, Bakery, that mimics shopping at a bakery, Danas Bakery, in a simplified manner. Danas Bakery

The goal of this part is to write a class, Bakery, that mimics shopping at a bakery, Danas Bakery, in a simplified manner. Danas Bakery sells four kinds of items, pastries, coffees, sandwiches, and loaves of bread. The prices are $4.5, $3.0, $6.0, and $7.0. The program receives the number of items the user purchases for each kind, computes the subtotal, computes the tax (the tax rate is 7%), computes the total, and greets off the customer. The program will report the subtotal after receiving the number of purchase for each kind. We show next an example of running the program.

Welcome to Dana's Bakery! Pastries are 4.5 dollars each. Coffees are 3.0 dollars each. Sandwiches are 6.0 dollars each. Loaves of breads are each 7.0 dollars. How many pastries? 5 Subtotal is 22.5 dollars. How many coffees? 4 Subtotal is 34.5 dollars. How many sandwiches? 2 Subtotal is 46.5 dollars. How many loaves? 1 Subtotal is 53.5 dollars. Tax is 3.74 dollars. Total is 57.24 dollars. Thank you for coming. See you soon!

We will use the following variables in the program: int variables pastries, coffees, sandwiches, and loaves for storing the numbers of orders for pastries, coffees, sandwiches, and loaves, respectively, and double variables subtotal, tax, and total for the subtotal, the tax, and the total of the purchase. In computing the tax, we can use the following formula (int)( subtotal * 0.07 * 100 ) / 100.0 The formula inside the parenthesis computes the tax in cents, uses the (int) to round it down, and then runs the amount in dollars. With the use of a simple subtotal * 0.07, the above example would produce the following instead.

Welcome to Dana's Bakery! Pastries are 4.5 dollars each. Coffees are 3.0 dollars each. Sandwiches are 6.0 dollars each. Loaves of breads are each 7.0 dollars. How many pastries? 5 Subtotal is 22.5 dollars. How many coffees? 4 Subtotal is 34.5 dollars. How many sandwiches? 2 Subtotal is 46.5 dollars. How many loaves? 1 Subtotal is 53.5 dollars. Tax is 3.7450000000000006 dollars. Total is 57.245 dollars. Thank you for coming. See you soon!

How ugly the tax and total values look!Java

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago