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);
}
}