Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, code needed listed on bottom, code has tax methods, just not implmented. Edit your OnlineBookOrderLastName.java program. Copy and paste it into the same Week

Java, code needed listed on bottom, code has tax methods, just not implmented.

Edit your OnlineBookOrderLastName.java program. Copy and paste it into the same Week 5 project with the new name - BookOrderSentinelLastName.java. Remove the prompt for the user to provide the number of books purchased. Modify your program to receive book prices until a sentinel value is entered. (Be sure to tell your user what the sentinel value is so they can type it to indicate they are finished with entering input.) After the sentinel value is entered, compute the total book order total and return the following to the user.

As book prices are entered, you'll need to have some way to capture the number of books they ordered and the running subtotal for use in the total book order price.

Compute the tax and shipping as usual (tax is 5.5 percent of the total book price & shipping charge is $1.50 per book). The price of the order is still the sum of the total book price, the tax, and the shipping charge. Output a receipt formatted as the following:

Enter the book price and press enter or type 999 when you are finished added books: 12.22

Enter another book price and press enter or type 999 when you are finished added books: 12.00

Enter another book price and press enter or type 999 when you are finished added books: 13.33

Enter another book price and press enter or type 999 when you are finished added books: 999

Number of books purchased: 3

Book Subtotal: $37.55

Tax: $2.07

Shipping: $4.50

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

Order Total: $44.12

IMPORTANT TESTING NOTE: Double check your math to make sure your sentinel value isn't being added into the book total and that you don't end up with an extra book in the number of books purchased. You can prevent that by setting up your loop correctly. If you are subtracting 1 from the book count or subtracting the sentinel value, you do not have your loop set up correctly.

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(); double sub = 0; for (int i = 0; i < book; i++) { System.out.print("Enter the book price for Book " + (i + 1) + ": "); double bookCost = in.nextDouble(); sub += bookCost; } 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)); } }

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

List the components of the strategic management process. page 72

Answered: 1 week ago