Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have my code already, I need a JUNIT 5 Test code. I have pasted the code below Retrieve WidgetOrderYourLastName (from Topic 3). Create a

I have my code already, I need a JUNIT 5 Test code. I have pasted the code below

Retrieve WidgetOrderYourLastName (from Topic 3). Create a JUnit Test case to test your method. Write three tests using the data and results below (note that you will need to come up with one of your own tests, as only two are provided).

A hint: You can give your assertEquals method some leeway so you don't need the exact values by using this method:

assertEquals(double expected, double actual, double delta); Asserts that two doubles or floats are equal to within a positive delta.

If you ran your methods (with the main method without the printf( ) or DecimalFormat), you'll see that you get several decimal points. One way that we can account for small differences is by giving the assertEquals method a delta - 0.01. This means that if the return result is within 0.01 of the expected value, return true. The assertion method would look something like:

assertEquals(expected, actual, 0.01);

Create a JUnit test case to test your newly created method. Use the test data below to confirm you are receiving the correct values.

Test Data #1 Test Data #2 Test Data #3

Enter the number of widgets purchased: 5

------------------------

Order Total: $54.70

Enter the number of widgets purchased: 8

------------------------

Order Total: $87.52

You create

Submit the WidgetOrderYourLastName.java and your WidgetOrderYourLastNameTest.java to the assignment below. Make sure you have both of the files attached. Both files are worth 10 points. I have my code already, I need a JUNIT 5 Test code

Here is my code: I NEED A JUNIT 5 TEST CODE

import java.util.Scanner;

public class WidgetOrderSivakumar3 { public static void main(String[] args) { final double TAX_RATE = 0.055; final double SHIPPING = 0.040; int numberofwidgets; double subtotal=0.0; double tax = 0.0; double shipping = 0.0; double total = 0.0; Scanner sc = new Scanner(System.in); //Reading input from user System.out.print("Enter the number of widgets purchased:: "); numberofwidgets =sc.nextInt(); //Printing the read values System.out.printf("Number of books purchased: %d ", numberofwidgets); subtotal = ((numberofwidgets * 10) - TAX_RATE); System.out.printf("Subtotal:$%.2f ", subtotal); //Calculating tax, shipping cost and total tax = subtotal*TAX_RATE; shipping = subtotal * SHIPPING; total = subtotal + tax + shipping; //Printing results in formatted manner using printf function System.out.printf("Tax: $%.2f ", tax); System.out.printf("Shipping: $%.2f ", shipping); System.out.println("----------------------"); System.out.printf("Order Total :$%.2f ", total); } }

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions