Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In JUnit 5 Create JUnit tests for the calculateTaxRate(ProductType productType) method based upon the following requirements: Invoke this method by passing a ProductType (which is

In JUnit 5

Create JUnit tests for the calculateTaxRate(ProductType productType) method based upon the following requirements: Invoke this method by passing a ProductType (which is a public enum found in the SampleClass class). The method should return the appropriate tax rate as shown below. (The tax rate is returned as a decimal value).

Product Type Tax Rate
Bakery 5%
Beverage 7.5%
Dairy 4%
Deli 6.5%
Meat 6.5%
Pharmacy 3.5%
Produce 4.5%
Seafood 6%
package assignment; import assignment.exceptions.InvalidProductException; import assignment.exceptions.InvalidValueException; import static assignment.SampleClass.ProductType.*; public class SampleClass { // Ctrl-Shift-T public enum ProductType { Bakery, Beverage, Pharmacy, Produce, Deli, Meat, Seafood, Dairy, Miscellaneous } public double calculateTaxRate(ProductType productType) throws InvalidProductException { if (productType == Bakery) { return 0.05; } if (productType == Beverage) { return 0.075; } if (productType == Pharmacy) { return 0.035; } if (productType == Produce || productType == Dairy) { return 0.04; } if (productType == Deli || productType == Meat) { return 0.065; } if (productType == Seafood) { return 0.06; } throw new InvalidProductException("Unknown product type: " + productType); }

package assignment.exceptions; public class InvalidProductException extends Exception { public InvalidProductException(String s) { super(s); } } 

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