Question
import java.util.Scanner; public class BookOrderYourlastname { static double order_total(int number_of_books,int subtotal){ double total_bill=0,shipping_cost=0,total_tax=0; shipping_cost=2.75*number_of_books; total_tax=0.12*subtotal; total_bill=shipping_cost+total_tax+subtotal; return total_bill; } public static void main(String[] args) {
import java.util.Scanner;
public class BookOrderYourlastname { static double order_total(int number_of_books,int subtotal){ double total_bill=0,shipping_cost=0,total_tax=0; shipping_cost=2.75*number_of_books; total_tax=0.12*subtotal; total_bill=shipping_cost+total_tax+subtotal; return total_bill; } public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { int number_of_books, subtotal; System.out.println("Enter the number of books"); number_of_books = sc.nextInt(); System.out.println("Enter the subtotal"); subtotal = sc.nextInt(); double total_bill = order_total(number_of_books, subtotal); System.out.println("The total_bill is :" + total_bill);
LANGUAGE = JAVA
Online Book Order (method)
Retrieve BookOrderYourLastName (from Topic 3). Create a JUnit Test case to test your method. Write three tests using the data and results below.
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 |
Enter the number of books purchased: 5 Enter the book order subtotal: 68.45 Number of books purchased: 5 Book Subtotal: $68.45 ------------------------ Order Total: $79.71 | Enter the number of books purchased: 8 Enter the book order subtotal: 125.37 Number of books purchased: 8 Book Subtotal: $125.37 ------------------------ Order Total: $144.27 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started