Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

3 questions in total Problem 1 Calculating Sales Tax Different grocery products have separate tax associated with them in Canada. In this problem you will

image text in transcribedimage text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

3 questions in total

Problem 1 Calculating Sales Tax Different grocery products have separate tax associated with them in Canada. In this problem you will write a program that will read the product information and quantity to calculate the related sales tax. Your program will print the prices before and after tax, and the product information according to the examples below. You must limit the output to two decimal points using the printf method. Products have three categories: 0 - Produce (no tax) 1 - Dairy (no tax) 2 - Processed (5% tax) 3 Drinks (15% tax; water is tax free) Comments: We expect students to use comments in their code and include a header comment in all assignment files! This will be graded as it is important for code readability. The header comment should be placed first in the file and must conform to the following format: /* CSCI 1105 Assignment X * First Last Names BOOxxxxxx * A brief description of the program * Different grocery products have separate tax associated with them in Canada. In this problem, you will write a program that will read the product information and quantity to calculate the related sales tax. Your program will print the prices before and after tax, and the product information according to the examples below. You must limit the output to two decimal points using the printf method. Examples: Input Pepsi 3 1.25 10 Output Item: Pepsi Cost: 1.25 CAD Quantity: 10 Tax: 1.87 CAD Total: 14.37 CAD Invalid category, please start again Carrot 5.50 3 Some grocery stores have special discounts for customers who buy multiple items of the same product. Problem 2 will extend the code from problem one to add this functionality. Your program will apply the discount on the price before tax. Each category has its unique discount value and number of items needed: O O O Produce: 0 - 4 items: 0% 5 10 items: 10% 11+ items: 15% Dairy 0-2 items: 0% O 3 - 7 items: 3% 8+ items: 5% Processed and Drinks: No discount O O Your program output would be the same as problem one if there were no discount applied. If the customer received the discount, your program must print "(MULTI DISCOUNT)" after the product's price. Examples: Input Spinach 0.77 9 Output Item: Spinach Cost: 0.77 CAD (MULTI DISCOUNT) Quantity: 9 Tax: 0.00 CAD Total: 6.24 CAD Item: ChocolateMilk Cost: 2.99 CAD Quantity: 2 Tax: 0.00 CAD Total: 5.98 CAD ChocolateMilk 1 2.99 2 You can write this bonus problem if you want an extra challenge. There are very few marks associated with it. This problem extends from problem 2. Because Java is a strongly typed language, the user must input compatible types. Example: If we ask for an int using nextInt (), the user must input an int; otherwise, Java will throw an exception, and our program will break. In this bonus problem, you will write code to deal with those pesky users who cannot follow instructions To solve this problem, you will have to use try/catch blocks and look for the exception thrown when we input the wrong type. (Hint: to find the name of this exception, run P2 and type a double or a String in the category value). This problem is a sort of challenge; therefore, it is up to you do explore the book or Java's documentation to understand how try/catch blocks function. If the user inputs the wrong data type, your program should output: "Invalid input type! Java expects that you type the correct type" and finish

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

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago