/* InvRpt1.BAS CIS 111 David Klick October 8, 2007 This program creates an inventory report from the inventory file created using MakeInv1.java. */ public class InvRpt1 extends CIS111App { public static void main(String[] args) { int numrecs = 0; double amtcost = 0.0; double amtsale = 0.0; double sumcost = 0.0; double sumsale = 0.0; // Record fields String sku, desc; int loc, qoh; double cost, price; println("Creating Inventory Report file (InvReport.txt)"); SequentialFile outfile = new SequentialFile("InvReport.txt", FileMode.OUTPUT); outfile.println(" Inventory Analysis"); outfile.println(" ------------------"); outfile.println(); outfile.println(" Total"); outfile.println("Stock Unit Selling Quantity Total Selling"); outfile.println("No. Description Cost Price On Hand Item Cost Price"); outfile.println("----- ----------- ---- ------- -------- --------- -------"); SequentialFile infile = new SequentialFile("invdata.txt", FileMode.INPUT); while (!infile.eof()) { sku = infile.readString(); loc = infile.readInt(); desc = infile.readString(); cost = infile.readDouble(); price = infile.readDouble(); qoh = infile.readInt(); amtcost = qoh * cost; amtsale = qoh * price; sumcost = sumcost + amtcost; sumsale = sumsale + amtsale; outfile.printf("%-4s %-12s %6.2f %7.2f %4d %8.2f %8.2f\n", sku, desc, cost, price, qoh, amtcost, amtsale); } outfile.println(); outfile.printf("%-42s %9.2f %9.2f\n", "Totals", sumcost, sumsale); outfile.println("Report complete"); infile.close(); outfile.close(); println("Report file created"); } }