Question

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 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.

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

bookPurchase.java

import java.util.Scanner;

public class bookPurchase{

public static void main(String args[]){

Scanner bookSr = new Scanner(System.in);

System.out.println("Enter the number of books purchased:");

int noBooks = bookSr.nextInt();

int i=0;

double total = 0;

while(i<noBooks){

i++;

System.out.println("\nEnter the book price for Book "+i);

total = total + bookSr.nextDouble();

}

System.out.println("\n----------------------------\n");

System.out.println("Number of books purchased "+noBooks);

System.out.println("Book Subtotal is: $"+total);

System.out.println("\n----------------------------\n");

// There was no information given about calculating Order Total, hence I've assumed tax

// Tax has been added to total, and adding it to total

// Imp Comment : orderTotal is different as tax % is assumed percentage

double tax = ( total * 15 ) / 100;

double orderTotal = total + tax;

System.out.println("Order Total: $"+ orderTotal);

bookSr.close();

}

}

Screenshots of working output

1.

2.

Please let me know in the comments if any additions are needed.

Please rate.

Add a comment
Know the answer?
Add Answer to:
Modify your Online Book Order program from week 4 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 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...

  • 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...

  • Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number...

    Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number to search (until ^D) and display the position of the number in the sorted vector. Try your program for the following user input: 1 15 18 40 30 50 ^D The output should be: -1 2 -1 7 5 -1 int binary_search(vector<int> v, int from, int to, int value) { if (from > to) return -1; int mid = (from + to) / 2;...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • CM245 Lab 4 (Chapter 12) Submit online through D2L Implement solutions using the appropriate concepts from...

    CM245 Lab 4 (Chapter 12) Submit online through D2L Implement solutions using the appropriate concepts from Chapter 12. There is no need for any UML for this lab. Provide your implementation (java source code) and the output for each of the tests. There should be one class for exercises 12.2 and 12.3 and two classes for 12.4. I prefer one output file per programming exercise. For each problem you must handle the exception. 12.2 (InputMismatchException) Write a program that prompts...

  • C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show...

    C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...

  • 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...

  • 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...

  • 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...

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