Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create JUnit tests for the calculateTaxRate (ProductType productType) and getDensityQualifier (int dpi) methods of the provided class SampleClass (described below). Your goal is to create

Create JUnit tests for the calculateTaxRate (ProductType productType) and getDensityQualifier (int dpi) methods of the provided class SampleClass (described below). Your goal is to create JUnit tests that result in 100% code coverage.

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%

Create JUnit tests for the getDensityQualifier(int dpi) method based upon the following requirements: Invoke this method by passing an integer screen density value (referred to as dpi). The method should return the appropriate screen density qualifier value as shown below. (The screen density qualifier is returned as a String value).

Density Qualifier Description
ldpi Up to 120dpi
mdpi Up to 160dpi
hdpi Up to 240dpi
xhdpi Up to 320dpi
xxhdpi Up to 480dpi
xxxhdpi Up to 640dpi
tvdpi For televisions, exactly 213dpi
nodpi Any other unspecified positive value

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); } public String getDensityQualifier(int dpi) throws InvalidValueException { if (dpi <= 0) throw new InvalidValueException("DPI value must be greater than zero"); if (dpi == 213) { return "tvdpi"; } if (dpi <= 120) { return "ldpi"; } if (dpi <= 160) { return "mdpi"; } if (dpi <= 240) { return "hdpi"; } if (dpi <= 320) { return "xhdpi"; } if (dpi <= 480) { return "xxhdpi"; } if (dpi <= 640) { return "xxxhdpi"; } return "nodpi"; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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