Question

Modify your Online Book Order program from week 5 to prompt the users for the number...

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

This is what I had originally. Not sure if I did it right during that week. (numbers are interchangeable, I just used these first time round)

public class BookOrderKirkpatrick {
   public static void main(String[] args) {
       int numBooksPurchased = 5;
       double bookPrice = 10.00;
   double taxPercent = 0.055;
   double shippingCostPerBook = 1.50;
   double taxTotal = (taxPercent * bookPrice);
       double totalBookPrice = (bookPrice + taxTotal);
       double shippingTotal = (numBooksPurchased * shippingCostPerBook);
       double orderTotal = (numBooksPurchased * totalBookPrice + shippingTotal);
      
      
       System.out.println (orderTotal);
      

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

BookOrderKirkpatrick.java :


//import package
import java.util.*;

//java class
public class BookOrderKirkpatrick {
   // entry point of the program , main() method
   public static void main(String[] args) {
       // creating object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user number of books they are purchasing
       System.out.print("Enter the number of books purchased:");
       // reading books
       int numBooksPurchased = sc.nextInt();
       // declaring variable to store Subtotal
       double Subtotal = 0;
       // using for loop
       for (int i = 0; i < numBooksPurchased; i++) {
           // asking user cost of each book
           System.out.print("Enter the book price for Book " + (i + 1) + " : ");
           // reading book cost and storing in the Subtotal
           Subtotal += sc.nextDouble();
       }
       // print number of book purchased
       System.out.println("Number of books purchased:" + numBooksPurchased);
       System.out.println("Book Subtotal: $"+Subtotal);// print book total
       double taxPercent = 0.055;
       double shippingCostPerBook = 1.50;
       double taxTotal = (taxPercent * Subtotal);
       double totalBookPrice = (Subtotal + taxTotal);
       double shippingTotal = (numBooksPurchased * shippingCostPerBook);
       double orderTotal = (totalBookPrice + shippingTotal);
       System.out.println("Order Total: $"+orderTotal);// print book order total
   }
}

==================================

Output :Compile and run BookOrderKirkpatrick.java to get the screen as shown below

Screen 1:BookOrderKirkpatrick.java

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Modify your Online Book Order program from week 5 to prompt the users for the number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Modify your Online Book Order program from week 4 to prompt the users for the number...

    Modify your Online Book Order program from week 4 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...

  • Language = Java Create a program to receive book prices until a sentinel value is entered....

    Language = Java Create a 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...

  • Write a C++ program that asks for the following information about a book order from the...

    Write a C++ program that asks for the following information about a book order from the console: • Title • Author • ISBN (hint: careful about what data type to use - validate 9 or 13 characters) • Price (validate number < 400) • Quantity (number of books to purchase – validate > 0 and < 100) • Fiction/Non-Fiction (‘N’ or ‘F’ - validate) • Genre (‘R’ romance, ‘D’ drama, ‘M’ mystery – validate) Make use of the following data...

  • Write a complete Java program with methods that prompt user for the number of floors, rooms,...

    Write a complete Java program with methods that prompt user for the number of floors, rooms, occupied rooms in a hotel. You must validate floors, rooms, occupied rooms. Compute vacant rooms, occupancy rate on each floor and display rooms, occupied rooms, vacant rooms and occupancy rate for each floor. Use the given method names. See validation rules below: 1. getFloors(). This method prompts user for number of floors in a hotel and returns floors to the caller. 2. testFloors(floors). Do...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • JAVA Objective : • Learning how to write a simple class. • Learning how to use...

    JAVA Objective : • Learning how to write a simple class. • Learning how to use a prewritten class. • Understanding how object oriented design can aid program design by making it easier to incorporate independently designed pieces of code together into a single application. Instructions: • Create a project called Lab13 that contains three Java file called Book.java , Bookstore.java and TempleBookstore.java • I’ve provided a screenshot of how your project should look like. • Be sure to document...

  • 8.7 LAB*: Program: Online shopping cart (Part 2)

    8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...

  • Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix...

    Problem 1 Write your code in the file MatrixOps.java. . Consider the following definitions from matrix algebra: A vector is a one-dimensional set of numbers, such as [42 9 20]. The dot product of two equal-length vectors A and B is computed by multiplying the first entry of A by the first entry of B, the second entry of A by the second entry of B, etc., and then summing these products. For example, the dot product of [42 9...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • Project: Using Java API Classes Page 3 of 5 SpaceTicket.java Requirements: The purpose of this program is accept coded...

    Project: Using Java API Classes Page 3 of 5 SpaceTicket.java Requirements: The purpose of this program is accept coded space ticket information as input that includes the ticket price, category, time, date, and seat, followed by the description of the travel. Note that the eight digits for price have an implied decimal point. The program should then print the ticket information including the actual cost, which is the price with discount applied as appropriate: 25% for a student ticket (s),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT