I have a bookstore application, but I cannot show the maximum and minimum and maximum price of the book, in the end the program. Please see my codes below.
import java.util.*;
public class Book{
public static void main(String args[]){
int numOfBook;
double totalCost = 0;
String expBookTitle = "";
double expBookPrice = 0;
String cheapBookTitle = "";
double cheapBookPrice = 0;
Scanner input = new Scanner(System.in);
System.out.println("Welcome to SAJID's Book Shop");
System.out.print("How many book would you like to store: ");
numOfBook = input.nextInt();
String[] book = new String[numOfBook];
double[] bookPrice = new double[numOfBook];
for(int i=0;i<book.length;i++)
{
System.out.print("Please enter book name: ");
book[i] = input.next();
System.out.print("Please enter book price: ");
bookPrice[i] = input.nextDouble();
System.out.println();
totalCost += bookPrice[i];
if(bookPrice[i] == expBookPrice)
{
expBookPrice = bookPrice[i];
expBookTitle = book[i];
System.out.println("Expensive book price: " + expBookPrice);
System.out.println("Expensive book title: " + expBookTitle);
if(bookPrice[i] <= expBookPrice)
{
cheapBookPrice = bookPrice[i];
cheapBookTitle = book[i];
System.out.println("Cheap book price: " + cheapBookPrice);
System.out.println("Cheap book title: " + cheapBookTitle);
}
}
}
}
}