Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fenwick Books has asked you to create a program to help calculate a receipt for

ID: 3666386 • Letter: F

Question

Fenwick Books has asked you to create a program to help calculate a receipt for books purchased. Wirte a Java program that will take in the number of books ordered and the total price of all books as user input. Then, the program should perform the following calculations: Calculate the sales tax associated with the book order based on a rate of 6% Calculate the cost of shipping ($1.50 per book) Calculate the grand total cost of the order, including shipping and tax Finally, the program must print a receipt containing the number of books purchased and the grand total cost of the order. Printed dollar amounts must be formatted to two decimal places. The example run below shows how the program would run. Note, user input is denoted in orange. Enter the number of books purchased: 3 Enter the total price of all books: 106.10 **Fenwick Books - Receipt** Number of Books Purchased: 3 Grand Total: $116.97 Note: For input/output, you must use the JOptionPane class. For this lab only, you may assume the user will only enter in valid information. For example, you do not need to account for a negative number of books purchased.

Explanation / Answer

import java.util.Scanner;

public class Calculate {

   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the number of books purchased: ");
       int numberOfBook = sc.nextInt();
       System.out.println("Enter the total price of all books: ");
       double totalPrice = sc.nextFloat();
       double saleTax = totalPrice*0.06;
       double shippingCost = numberOfBook*1.50;
      
       double grandTotal = totalPrice + saleTax + shippingCost;
       System.out.println("**Fenwick Books - Receipt**");
       System.out.println("Number of Books Purchased: "+numberOfBook);
       System.out.printf("Value: %.2f", grandTotal);
   }
}

/*

Output:

Enter the number of books purchased:
3
Enter the total price of all books:
106.10
**Fenwick Books - Receipt**
Number of Books Purchased: 3
Value: 116.97

*/