Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A book seller provides online sales service for clients. In a prototype case, there are five books for sale. Each
book is identified by number 1 to 5 know as bookId. Books have fixed prices.
bookId 1 is priced at $20.85, bookId 2 at $14.50; bookId 3 at $19.30, bookId 4 at $41.25 and bookId 5 is priced
at $61.65.
Write a program that reads pairs of inputs for “bookId” and “quantity sold” and calculates total sale value of
each book using formula: sale value = book price * quantity sold. Then the program finally calculates
accumulative total of all books sold during a business day

What I have tried:

import java.util.Scanner;
public class MyBookstore {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    MyBookstore s = new MyBookstore();


    int y = 1;
    int user_choice = 5;
   

    do {
        //display menu to user
        //ask user for his choice and validate it (make sure it is between 1 and 5)
        System.out.println();
        System.out.println("1) Enter bookId (1-5 or 0 to stop): ");
		 System.out.println("2) Enter book quantity sold: ");
Posted
v3
Comments
Hey Neha,

No one here will help with this type of broad question. You can get help by explaining what you have tried and what is exactly not working.

Thanks,
Tadit
Richard MacCutchan 22-Oct-22 4:07am    
Use an array or List type to hold the prices for the different book ids. Then when you read the book id and the quantity it is a simple calculation to give the sale amount. You also need to add that to a running to total to print at the end of the day.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900