Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8034619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:04:49+00:00 2026-06-05T02:04:49+00:00

I have successfully completed, and no problems with the program, everything works just fine,

  • 0

I have successfully completed, and no problems with the program, everything works just fine, except it does not show the the maximum and minimum price of the book. But, I do not want the program like this.

Currently the program consists of pre-defined array that consists of book name, that is, whenever a user enters input for a book, the program shows the book name and price of the book. So, I am thinking of something different, that is without pre-storing the book names and prices in the array.

Whatever name the user key-in for the book, that book name will be stored as an array along with the price. And the loop will be three times, that is after 1 input of book name and price, the user will again be prompted to enter book name, and last the the total number books and price will be displayed along with the maximum and minimum prices of the book, the user purchased.

Can anyone help me with this? Please see my coding below:

import java.util.Scanner;
public class BookStore {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        String[] books = {"Introduction To Java","Artificial Intlegence","Web Programming","Introduction To Database","English Speech","Introduction To C#"};

        double[] prices ={100,50,25,45,60,90}; 

        System.out.println("Welcome to SAJID's Book Shop");
        System.out.println();
        System.out.println("Please select the the book and write the number of the book :");
        System.out.println();
        System.out.println("1.Introduction To Java");
        System.out.println("2.Artificial Intlegence");
        System.out.println("3.Web Programming");
        System.out.println("4.Introduction To Database");
        System.out.println("5.English Speech");
        System.out.println("6.Introduction To C#");
        System.out.println();

        System.out.println("Total Number Of Books "+books.length);
        int totalBook;
        totalBook = books.length;

        double totalPrice=0;    
        int i=0;            
        while(i<=5){
            totalPrice+=prices[i];
            i++;
        }

        System.out.println("Total Price:$" + totalPrice);

        int bookTitle;
        System.out.print("Enter book Number: ");
        bookTitle = input.nextInt();

        if(bookTitle == 0){
            System.out.println("Book name: "+books[0]);
            System.out.print("Book price:$"+prices[0]);
            }

        if(bookTitle == 1){

            System.out.println("Book name: "+books[1]);
            System.out.print("Book price:$"+prices[1]);
        }
        if(bookTitle == 2){

            System.out.println("Book name: "+ books[2]);
            System.out.print("Book price:$"+prices[2]);
        }
        if(bookTitle == 3){

            System.out.println("Book name: "+books[3]);
            System.out.print("Book price:$"+prices[3]);
        }
        if(bookTitle == 4){

            System.out.println("Book name: "+books[4]);
            System.out.print("Book price:$"+prices[4]);
        }
        if(bookTitle == 5){

            System.out.println("Book name: "+books[5]);
            System.out.print("Book price:$"+prices[5]);
        }

        /*double min=0;
        for(i=0;i<books.length-1;i++){

            if(books[i] =< books[i++]){
                min=books[i];
                minBook = i;
            }*/
        }

        //System.out.print("Cheapest book: " + min);
    }       
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:04:50+00:00Added an answer on June 5, 2026 at 2:04 am

    That probably does not your question (which I have not really understood) but this is too long for a comment. You could start by replacing all your ifs by:

    if(bookTitle >= 0 && bookTitle <= 5){
        System.out.println("Book name: "+books[bookTitle]);
        System.out.print("Book price:$"+prices[bookTitle]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have just completed implementing a successful but problematic project. We want to get
I have successfully compiled lua in my mac. It works. It runs. Now, I
I have successfully completed an AQA Computing exam (June 2011) in Delphi. Out of
celery works wonderfully! :) e.g. results are returned with no problems! Unfortunately celerycam does
Have successfully gotten the csrf middleware working in express as per previous SO questions.
I have successfully managed to get System.Speech.Synthesis to read English text in arbitrary voices
I have successfully implemented interop beftween Win32 application and managed .Net dll as described
I have successfully upgraded an MFC application which was compiled with an old version
I have successfully used the Excel and Word addin templates in Visual studio 2008
I have successfully set up FILESTREAM on my SQL 2008 server; however I've noticed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.