I'm trying to add the cost of books from a text file and print them. However, I'm getting [Ljava.lang.Double;@55f96302
where my values should be.
Here is my current code:
System.out.println("Welcome to the libary book search system.");
System.out.println("------------------------------------------");
if(choice.equals("Text File")) {
//String sc = null;
System.out.println("Title\t\t\tAuthor\t\t\tPrice\t\t\tBookPublisher\t\t\tISBN");
System.out.println("=====\t\t\t======\t\t\t=====\t\t\t=============\t\t\t====");
int count = 0;
try {
File Fileobject = new File ("E:\\text files for java\\BooksToImport.txt");
Scanner sc = new Scanner(Fileobject);
// Read and display each line of the file
while(sc.hasNextLine()) {
String line2 = sc.nextLine();
Scanner sc2 = new Scanner(line2);
sc2.useDelimiter("-");
System.out.println(line2);
while(sc2.hasNext()) {
BookTitle[count] = sc2.next();
System.out.println(BookTitle[count]);
BookAuthor[count] = (sc2.next());
System.out.println(BookAuthor[count]);
BookPrice[count] = sc2.next();
System.out.println(BookPrice[count]);
BookPublisher[count] = sc2.next();
System.out.println(BookPublisher[count]);
ISBN[count] = sc2.next();
System.out.println(ISBN[count]);
}
sc2.close();
count++;
}
//for(int index=0;index<count;++index) {
//BookPrice2[index]=Double.parseDouble(BookPrice[index]);
//System.out.println(BookPrice2[index]);
//}
sc.close();
System.out.println("----------------------");
System.out.println("Totals of the Text File:");
System.out.println("----------------------");
System.out.println("Total Numbers Of Books:" + NUMBEROFBOOKS);
System.out.println("Total Cost Of Books:"+ BookPrice2 );
System.out.println("Maximum Cost Of A Book:");
System.out.println("Minimum Cost Of A Book:");
System.out.println("Average Cost Of A Book:");
System.out.println("Total number of valid books:");
System.out.println("Total number of invalid books:");
} catch (FileNotFoundException e) {
System.out.println("File does not exist");
}
}
Here is my text file:
The Hunger Games - Suzanne Collins - 5 - Scholastic Press - 9781921988752
OOP programming - Graham Winter - 32 - Oriely - 9876543219
Harry potter - Jk Rowling - 10 - Bloomsbury - 9788700631625
Here is what is being displayed by my java program:
Enter what you want to do: Type 'Input' for user input or 'Text File' to read from file.
Text File
Welcome to the libary book search system.
------------------------------------------
Title Author Price BookPublisher ISBN
===== ====== ===== ============= ====
The Hunger Games - Suzanne Collins - 5 - Scholastic Press - 9781921988752
The Hunger Games
Suzanne Collins
5
Scholastic Press
9781921988752
OOP programming - Graham Winter - 32 - Oriely - 9876543219
OOP programming
Graham Winter
32
Oriely
9876543219
Harry potter - Jk Rowling - 10 - Bloomsbury - 9788700631625
Harry potter
Jk Rowling
10
Bloomsbury
9788700631625
----------------------
Totals of the Text File:
----------------------
Total Numbers Of Books:3
Total Cost Of Books:[Ljava.lang.Double;@55f96302
Maximum Cost Of A Book:
Minimum Cost Of A Book:
Average Cost Of A Book:
Total number of valid books:
Total number of invalid books: