I'm writing some code that is supposed to print out a list of books that fit a criteria. But the problem is that the books the code gets to the point where the loop that checks and prints out matches starts. Then just skips over the whole loop. I tested the loop to see if it was runing at all and it doesn't seem to be.
System.out.println("List of textbooks: ");
NumberFormat fmt = NumberFormat.getCurrencyInstance(); //POST: converts numbers into currency form
for(int n = 0; n<11; n++){
for (int x=0;x<11;x++){
if (bookList[x] instanceof Textbook){
String newCourse = ((Textbook) bookList[x]).getCourse();
String courseName = courseList[n];
if(newCourse.equals(courseName)){
bookPrice = ((Textbook) bookList[x]).retailPrice();
System.out.printf("%-10s bbbsd %-10s %-10s %-10s \n",
((Textbook) bookList[x]).getCourse(),((Textbook) bookList[x]).getTitle(),
((Textbook) bookList[x]).getAuthor(),fmt.format(bookPrice));
retailSum = retailSum + bookPrice;
}
}
}
}
System.out.printf("Sum of retail book Prices: %-40s\n", fmt.format(retailSum));
This is the output I get
List of textbooks: Sum of retail book Prices: $0.00
Aucun commentaire:
Enregistrer un commentaire