/* InvRpt1R.BAS CIS 111 David Klick October 20, 2007 This program creates an inventory report from the inventory file created using MakeInv1R.java. */ public class InvRpt1R extends CIS111App { public static void main(String[] args) { double amtcost = 0.0; double amtsale = 0.0; double sumcost = 0.0; double sumsale = 0.0; println("Creating Inventory Report file (InvReportR.txt)"); SequentialFile outfile = new SequentialFile("InvReportR.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("----- ----------- ---- ------- -------- --------- -------"); Record rec = new Record(); RandomFile infile = new RandomFile("invdataR.dta", rec); for (long numrec=1; numrec<=infile.numberOfRecords(); numrec++) { rec = infile.get(numrec); amtcost = rec.quantity * rec.cost; amtsale = rec.quantity * rec.price; sumcost = sumcost + amtcost; sumsale = sumsale + amtsale; outfile.printf("%-4s %-12s %6.2f %7.2f %4d %8.2f %8.2f\n", rec.SKU, rec.description.substring(0,12), rec.cost, rec.price, rec.quantity, 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"); } } class Record { String SKU = "xxxx"; int location = 0; String description = "xxxxxxxxxxxxxxxxxxxx"; double cost = 0.0; double price = 0.0; long quantity = 0; public Record() {} public Record(String sku, int loc, String desc, double cost, double price, long qty) { SKU = sku; location = loc; description = desc; this.cost = cost; this.price = price; quantity = qty; } }