Just started java. The main code has no problem in it. The hihestPage and lowestPages both show correct values but im getting null on the bookmaxpage and bookminpage. Trying to get the Title name on both max and min page.
package Library;
import java.util.Scanner; import java.util.Arrays;
public class Library {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scan = new Scanner(System.in);
int i,j,number;
int count=0;
float highestPrice=0,total=0;
String bookmaxpage=" ",bookminpage=" ";
int highestPage=0;
float averageCost=0;
String Title[] = new String[20];
String Author[] = new String[20];
String Publisher[] = new String[20];
float Price[] = new float[20];
int Page[] = new int[20];
int ISBN[] = new int[20];
System.out.println("Enter the number of books that u want to enter : ");
number = scan.nextInt();
for(i=0;i<number;i++) {
System.out.println("Enter Details of the book. ");
System.out.println("Enter the title: ");
Title[i]=scan.next();
if(Title[i].equalsIgnoreCase("nomore")) {
break;
}
System.out.println("Enter the author: ");
Author[i]=scan.next();
System.out.println("Enter the publisher: ");
Publisher[i]=scan.next();
System.out.println("Enter the price: ");
Price[i]=scan.nextFloat();
System.out.println("Enter the pages: ");
Page[i]=scan.nextInt();
System.out.println("Enter the ISBN: ");
ISBN[i]=scan.nextInt();
total=total+Price[i];
count++;
}
for(i=0;i<Price.length;i++) {
if(Price[i]>highestPrice)
highestPrice = Price[i];
}
float lowestPrice= Price[0];
for(i=0;i<Price.length;i++) {
if(lowestPrice<Price[i])
lowestPrice = Price[i];
}
for(i=0;i<Page.length;i++) {
if(Page[i]>highestPage)
highestPage = Page[i];
bookmaxpage=Title[i];
}
int lowestPage= Page[0];
for(i=0;i<Page.length;i++) {
if(lowestPage<Page[i])
lowestPage = Page[i];
bookminpage=Title[i];
}
averageCost = total / number;
System.out.println("Title \t\t Author \t\t Publisher \t\t Price \t Pages \t ISBN");
System.out.println("======\t\t ====== \t\t ========= \t\t ===== \t ===== \t ====");
for(i=0;i<number;i++) {
System.out.println(Title[i] +" \t\t "+ Author[i] +" \t\t\t "+ Publisher[i] +" \t\t\t "+ Price[i] +" \t "+ Page[i] +" \t "+ ISBN[i]);
}
System.out.println("\n\n\n\nTotals ");
System.out.println("------------------------------");
System.out.println("Total number of books : " + count);
System.out.println("Total cost of books : " + total);
System.out.println("Maximum cost of a book : " + highestPrice);
System.out.println("Minimum cost of a book : " + lowestPrice);
System.out.println(bookmaxpage + " has the highest number of pages :" + highestPage);
System.out.println(bookminpage + " has the lowest number of pages :" + lowestPage);
System.out.println("Average Cost of books : " + averageCost);
}
}
Outcome : null has the maximum pages : 280. Looking for : Example has the maximum pages : 280
bookminpagedoesn't seem to be declared)