Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.File;
  3.  
  4. public class SodaSales{
  5. public static void main(String []args)throws Exception {
  6. File file = new File("D:\\Eclipse\\mcc\\src\\csc161\\sodasales.dat");
  7.  
  8. Scanner input = new Scanner(file);
  9.  
  10. int index = 0;
  11.  
  12. String[] brandArray = new String[5];
  13. int[] bottleSoldArray = new int [5];
  14. double[] bottleCostArray = new double [5];
  15. double[] bottleRetailArray = new double [5];
  16. String[] sortedBrandArray = new String[5];
  17. int[] sortedBottleArray = new int [5];
  18. double[] sortedBottleCost = new double [5];
  19. double[] sortedRetailCost = new double [5];
  20.  
  21. System.out.println(" Soda Sales");
  22. System.out.println("");
  23. System.out.println(" Bottles Cost Retail Profit Percent");
  24. System.out.println("Soda Sold Bottle Bottle Brand Sold of 150");
  25. System.out.println("---- ---- ------ ------ ------ ---------");
  26.  
  27.  
  28. int totalBottles = 0;
  29. float totalProfit = 0;
  30. float totalCost = 0;
  31. float totalRetail = 0;
  32. int brandTotal = 0;
  33.  
  34. while (input.hasNext()) {
  35. String brand = input.next();
  36.  
  37. while(!input.hasNextInt() && !input.hasNextFloat()){
  38. brand = brand + " " + input.next();//setting conditions to grab input with spaces AK
  39. brandTotal++; //adding to the total number of brands there are AK
  40. }
  41.  
  42. int bottles = input.nextInt();
  43. float cost = input.nextFloat();
  44. float retail = input.nextFloat();
  45. float profit = (float)bottles * (retail - cost);
  46. totalBottles += bottles;
  47. totalCost += cost;
  48. totalRetail += retail;
  49. totalProfit += profit;
  50.  
  51. brandArray[index] = brand;
  52. bottleSoldArray[index] = bottles;
  53. bottleCostArray[index] = cost;
  54. bottleRetailArray[index] = retail;
  55.  
  56.  
  57.  
  58. // for (int i = 0; i < brandArray.length - 1; i++) {
  59. // String a = brandArray[i];
  60. // String b = brandArray[i+1];
  61. //
  62. // if (a.compareTo(b)>0){
  63. // String temp = brandArray[i];
  64. // brandArray[i] = brandArray[i+1];
  65. // brandArray[i+1] = temp;
  66. // }
  67. //
  68. //
  69. // }
  70.  
  71. //printInfo(brand, bottles, cost, retail, profit);
  72. index++;
  73. }
  74. sortedBrandArray = brandArray;
  75. sortedBottleArray = bottleSoldArray;
  76. Arrays.sort(sortedBrandArray);
  77.  
  78. String sodaName = "";
  79. for (int i = 0; i < brandArray.length; i++)
  80. {
  81. sodaName = sortedBrandArray[i];
  82. for(int j = 0; j < brandArray.length; j++){
  83. if (brandArray[j].equals(sodaName))
  84. {
  85. index = j;
  86.  
  87.  
  88. System.out.print(sortedBrandArray[index]);
  89. System.out.print(" " + bottleSoldArray[index] + " ");
  90. System.out.printf("%.2f", + bottleCostArray[index]);
  91. System.out.print(" ");
  92. System.out.printf("%.2f", + bottleRetailArray[index]);
  93. System.out.print(" ");
  94. System.out.printf("%.2f",+ (float)(bottleRetailArray[index] * bottleSoldArray[index]) -
  95. (bottleCostArray[index]*bottleSoldArray[index]));
  96. System.out.print(" ");
  97. System.out.printf("%.2f",+ (float)((float)bottleSoldArray[index]/150*100));
  98. System.out.println("%");
  99. break;
  100. }
  101. }
  102. }
  103. System.out.print("Totals ");
  104. System.out.print(totalBottles);
  105. System.out.print(" ");
  106. System.out.printf("%.2f", ((float)totalCost/brandTotal));
  107. System.out.print(" ");
  108. System.out.printf("%.2f", ((float)totalRetail/brandTotal));
  109. System.out.println(" " + totalProfit);
  110.  
  111. input.close();
  112. }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement