Bitte helfen Sie mir, ich versuche, die Gesamtzahl der Bücher zu berechnen, basierend auf den Mengen aus einer Eingabedatei gelesen. Ich habe versucht, die Gesamtzahl der Bücher zu berechnen, aber im Moment produziert mein Code nur die letzte Menge, die er aus der Datei liest, als die Summe für totalBooks. Ich bin mir nicht sicher, was ich falsch mache, aber jede Anleitung würde sehr geschätzt werden. HierJava Total Books Berechnung
ist, was ich habe ...
Hinweis: Der Teil meines Programms, das ich zu beheben versuchen ist unter dem Kommentar // berechne Gesamt Bücher
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class BookstoreInventory
{
public static void main(String[] args)throws IOException
{
//Vaiable declartions
int edition, quanity;
double pricePerBook;
String isbn, author, title, publisherCode;
//Open the file and set delimiters
File file = new File("inventory.txt");
Scanner inputFile = new Scanner(file);
inputFile.useDelimiter("_|/|\\r?\\n");
//read from the file
while (inputFile.hasNext())
{
isbn = inputFile.next();
System.out.println(formatISBN(isbn)); //Need to move at end
author = inputFile.next();
System.out.println(getLastName(author)); //need to remove at end
title = inputFile.next();
System.out.println(truncateTitle(title)); //need to remove at end
edition = inputFile.nextInt();
System.out.println(edition(edition)); //need to remove at end
publisherCode = inputFile.next();
System.out.println(publisher(publisherCode)); //need to remove at end
quanity = inputFile.nextInt();
System.out.println(quanity); //need to remove at end
pricePerBook = inputFile.nextDouble();
System.out.println("$" + pricePerBook); //need to remove at end
//Calculate Total Books
int totalBooks = 0;
totalBooks += quanity;
System.out.println("Total books: " + totalBooks);
}
//Close the flie
inputFile.close();
}