Question: Java, code needed for this listed on bottom, Modify your Online Book Order program from week 5 to prompt the users for the number of

Java, code needed for this listed on bottom,

Modify your Online Book Order program from week 5 to prompt the users for the number of books they are purchasing. Using a for loop, prompt the user for the cost of each book and store it into a subtotal. Use the subtotal and the number of books to pass to your method. No changes should be needed to your method or parameters.

Output a receipt formatted as the following:

Enter the number of books purchased: 4

Enter the book price for Book 1: 12.34

Enter the book price for Book 2: 23.33

Enter the book price for Book 3: 11.00

Enter the book price for Book 4: 13.55

Number of books purchased: 4

Book Subtotal: $60.22

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

Order Total: $69.53

Verify that your tests still pass (they should - you made no changes to your method!) Submit your .java file. I don't need the tester file. It's worth 10 points.

Code and tests from last week:

Code:

import java.text.DecimalFormat; import java.util.Scanner; public class BookOrderLastName { public static double calculateTotal(int booksPurchased, double subTotal) { final double TAX_RATE = 0.055, SHIP_RATE= 1.5; double tax = TAX_RATE* subTotal; double ship = SHIP_RATE* booksPurchased; double total = subTotal + tax + ship; return total; } public static void main(String[] args) { DecimalFormat df = new DecimalFormat("##.00"); Scanner in = new Scanner(System.in); System.out.print("Enter the number of books purchased: "); int book = in.nextInt(); System.out.print("Enter the book order subtotal: "); double sub=in.nextDouble(); double total=calculateTotal(book, sub); System.out.println(" Number of books purchased: " + book); System.out.println("Book Subtotal: $" + df.format(sub)); System.out.println("_________________"); System.out.println("Order Total: $" + df.format(total)); } }

Test:

import static org.junit.Assert.*; import org.junit.Test; public class BookOrderLastNameTest { @Test public void testCalculateTotal() { double delta = 0.01; assertEquals(79.71, BookOrderLastName.calculateTotal(5, 68.45),delta); assertEquals(144.27, BookOrderLastName.calculateTotal(8, 125.37),delta); assertEquals(173.25, BookOrderLastName.calculateTotal(10, 150.0),delta); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!