Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.PrintWriter;
- import java.io.FileNotFoundException;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import java.util.StringTokenizer;
- public class Prog6
- {
- public static void main (String[] args) throws IOException, FileNotFoundException
- {
- String inputLine, item_name;
- Double item_cost,total_cost,avg;
- int warehouse_no,hi_count=0,rec_count=0,prev_warehouse = 0,page_num=1;
- StringTokenizer tokenizer = null;
- File input = new File ("C:\\java6.txt");
- Scanner inputFile = new Scanner (input);
- PrintWriter outfile =
- new PrintWriter(new FileWriter("C:\\Users\\nehem_000\\Desktop\\JAVA\\output.txt"));
- while(inputFile.hasNext())
- {
- inputLine = inputFile.nextLine();
- tokenizer = new StringTokenizer(inputLine, "@");
- warehouse_no = Integer.parseInt (tokenizer.nextToken());
- item_cost = Double.parseDouble (tokenizer.nextToken());
- item_name = tokenizer.nextToken();
- int total = 0,high = 0, low = 999;
- for(int ctr = 0;ctr>8; ctr ++)
- {
- int[] qty_array = new int[ctr];
- qty_array[ctr] = Integer.parseInt (tokenizer.nextToken());
- total += qty_array[ctr];
- if(qty_array[ctr]>high)
- {
- high = qty_array[ctr];
- }
- if(qty_array[ctr]> low)
- {
- low = qty_array[ctr];
- }
- }
- //Math
- total = total - (high+low);
- total_cost = total *item_cost;
- avg = total / 6.0;
- if(warehouse_no != prev_warehouse)
- {
- outfile.printf("\f");
- ReportHeader(page_num,warehouse_no, outfile);
- page_num++;
- prev_warehouse = warehouse_no;
- outfile.printf("%16s %14.2f %16d %15.2f %n", item_name, item_cost, total, avg);
- if(avg>90)
- {
- outfile.printf("HIGH INVENTORY");
- hi_count++;
- }
- outfile.printf("%n");
- rec_count++;
- }
- else
- {
- outfile.printf("%16s %14.2f %16d %15.2f %n", item_name, item_cost, total, avg);
- if(avg>90)
- {
- outfile.printf("HIGH INVENTORY");
- hi_count++;
- }
- outfile.printf("%n");
- rec_count++;
- }
- }
- outfile.printf("\f");
- outfile.printf(" Records Processed: %9d", rec_count);
- outfile.printf(" Records with high inventory: %9d", hi_count);
- outfile.close();
- inputFile.close();
- }
- public static void ReportHeader(int page_num, double warehouse_no,
- PrintWriter outfile) throws IOException
- {
- int[] warehouse_number = {101,102,103,105,108,109,201,204,207,210};
- String[] warehouse_name = {"MINNEAPOLIS","DENVER","WICHITA","KANSAS CITY","SALT LAKE CITY",
- "LITTLE ROCK","NASHVILLE","CALDWELL","DRURY","CORBIN"};
- String[] field ={"Item Name","Item Cost","Total Quanity","Average Quanity"};
- String localwarehouse_name = "";
- for(int ctr = 0; ctr<10;ctr++)
- {
- if(warehouse_number[ctr] == warehouse_no)
- {
- localwarehouse_name = warehouse_name[ctr];
- break;
- }
- else if (ctr>9)
- {
- localwarehouse_name = "UNKNOWN WAREHOUSE";
- }
- }
- String my_name = "Nehemiah Reese";
- String prog_name = "PROGRAM 6";
- String prog_title = "Warehouse Manager";
- String date = "4/27/2015";
- outfile.printf("Page %2s %10s %10s %10s %10s %n %n", page_num, my_name, prog_name, prog_title, date);
- outfile.printf("%15s %15s %15s %15s %n", field[0], field[1],field[2],field[3]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement