Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1.  
  2. import java.io.File;
  3. import java.io.PrintWriter;
  4. import java.io.FileNotFoundException;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.io.PrintWriter;
  8. import java.util.Scanner;
  9. import java.util.StringTokenizer;
  10.  
  11.  
  12. public class Prog6
  13. {
  14.  
  15. public static void main (String[] args) throws IOException, FileNotFoundException
  16. {
  17. String inputLine, item_name;
  18. Double item_cost,total_cost,avg;
  19. int warehouse_no,hi_count=0,rec_count=0,prev_warehouse = 0,page_num=1;
  20. StringTokenizer tokenizer = null;
  21.  
  22.  
  23.  
  24. File input = new File ("C:\\java6.txt");
  25. Scanner inputFile = new Scanner (input);
  26. PrintWriter outfile =
  27. new PrintWriter(new FileWriter("C:\\Users\\nehem_000\\Desktop\\JAVA\\output.txt"));
  28.  
  29. while(inputFile.hasNext())
  30. {
  31. inputLine = inputFile.nextLine();
  32. tokenizer = new StringTokenizer(inputLine, "@");
  33. warehouse_no = Integer.parseInt (tokenizer.nextToken());
  34. item_cost = Double.parseDouble (tokenizer.nextToken());
  35. item_name = tokenizer.nextToken();
  36. int total = 0,high = 0, low = 999;
  37.  
  38. for(int ctr = 0;ctr>8; ctr ++)
  39. {
  40. int[] qty_array = new int[ctr];
  41. qty_array[ctr] = Integer.parseInt (tokenizer.nextToken());
  42. total += qty_array[ctr];
  43.  
  44. if(qty_array[ctr]>high)
  45. {
  46. high = qty_array[ctr];
  47. }
  48.  
  49. if(qty_array[ctr]> low)
  50. {
  51. low = qty_array[ctr];
  52. }
  53. }
  54.  
  55. //Math
  56. total = total - (high+low);
  57. total_cost = total *item_cost;
  58. avg = total / 6.0;
  59.  
  60. if(warehouse_no != prev_warehouse)
  61. {
  62. outfile.printf("\f");
  63. ReportHeader(page_num,warehouse_no, outfile);
  64. page_num++;
  65. prev_warehouse = warehouse_no;
  66. outfile.printf("%16s %14.2f %16d %15.2f %n", item_name, item_cost, total, avg);
  67. if(avg>90)
  68. {
  69. outfile.printf("HIGH INVENTORY");
  70. hi_count++;
  71. }
  72. outfile.printf("%n");
  73. rec_count++;
  74. }
  75. else
  76. {
  77. outfile.printf("%16s %14.2f %16d %15.2f %n", item_name, item_cost, total, avg);
  78. if(avg>90)
  79. {
  80. outfile.printf("HIGH INVENTORY");
  81. hi_count++;
  82. }
  83. outfile.printf("%n");
  84. rec_count++;
  85. }
  86.  
  87.  
  88. }
  89. outfile.printf("\f");
  90. outfile.printf(" Records Processed: %9d", rec_count);
  91. outfile.printf(" Records with high inventory: %9d", hi_count);
  92. outfile.close();
  93. inputFile.close();
  94.  
  95. }
  96. public static void ReportHeader(int page_num, double warehouse_no,
  97. PrintWriter outfile) throws IOException
  98. {
  99. int[] warehouse_number = {101,102,103,105,108,109,201,204,207,210};
  100. String[] warehouse_name = {"MINNEAPOLIS","DENVER","WICHITA","KANSAS CITY","SALT LAKE CITY",
  101. "LITTLE ROCK","NASHVILLE","CALDWELL","DRURY","CORBIN"};
  102. String[] field ={"Item Name","Item Cost","Total Quanity","Average Quanity"};
  103.  
  104. String localwarehouse_name = "";
  105.  
  106. for(int ctr = 0; ctr<10;ctr++)
  107. {
  108. if(warehouse_number[ctr] == warehouse_no)
  109. {
  110. localwarehouse_name = warehouse_name[ctr];
  111. break;
  112. }
  113. else if (ctr>9)
  114. {
  115. localwarehouse_name = "UNKNOWN WAREHOUSE";
  116. }
  117. }
  118.  
  119.  
  120.  
  121. String my_name = "Nehemiah Reese";
  122. String prog_name = "PROGRAM 6";
  123. String prog_title = "Warehouse Manager";
  124. String date = "4/27/2015";
  125.  
  126. outfile.printf("Page %2s %10s %10s %10s %10s %n %n", page_num, my_name, prog_name, prog_title, date);
  127. outfile.printf("%15s %15s %15s %15s %n", field[0], field[1],field[2],field[3]);
  128.  
  129.  
  130. }
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement