Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. import java.util.Scanner;
  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. int index = 0;
  10.  
  11. String[] brandArray = new String[5];
  12. int[] bottleSoldArray = new int [5];
  13. double[] bottleCostArray = new double [5];
  14. double[] bottleRetailArray = new double [5];
  15.  
  16. System.out.println(" Soda Sales");
  17. System.out.println("");
  18. System.out.println(" Bottles Cost Retail Profit Percent");
  19. System.out.println("Soda Sold Bottle Bottle Brand Sold of 150");
  20. System.out.println("---- ---- ------ ------ ------ ---------");
  21.  
  22.  
  23. int totalBottles = 0;
  24. float totalProfit = 0;
  25. float totalCost = 0;
  26. float totalRetail = 0;
  27. int brandTotal = 0;
  28.  
  29. while (input.hasNext()) {
  30. String brand = input.next();
  31.  
  32. while(!input.hasNextInt() && !input.hasNextFloat()){
  33. brand = brand + " " + input.next();
  34. brandTotal++;
  35. }
  36.  
  37. int bottles = input.nextInt();
  38. float cost = input.nextFloat();
  39. float retail = input.nextFloat();
  40. float profit = (float)bottles * (retail - cost);
  41. totalBottles += bottles;
  42. totalCost += cost;
  43. totalRetail += retail;
  44. totalProfit += profit;
  45.  
  46. brandArray[index] = brand;
  47. bottleSoldArray[index] = bottles;
  48. bottleCostArray[index] = cost;
  49. bottleRetailArray[index] = retail;
  50.  
  51.  
  52. printInfo(brand, bottles, cost, retail, profit);
  53. index++;
  54. }
  55. System.out.print("Totals ");
  56. System.out.print(totalBottles);
  57. System.out.print(" ");
  58. System.out.printf("%.2f", ((float)totalCost/brandTotal));
  59. System.out.print(" ");
  60. System.out.printf("%.2f", ((float)totalRetail/brandTotal));
  61. System.out.println(" " + totalProfit);
  62.  
  63. input.close();
  64. }
  65.  
  66. public static void printInfo(String brand, int bottles, float cost, float retail, float profit) {
  67. System.out.print(brand);
  68. System.out.print(" " + bottles + " ");
  69. System.out.printf("%.2f", + cost);
  70. System.out.print(" ");
  71. System.out.printf("%.2f",+ retail);
  72. System.out.print(" ");
  73. System.out.printf("%.2f",+ (float)profit);
  74. System.out.print(" ");
  75. System.out.printf("%.2f",+ (float)((float)bottles/150*100));
  76. System.out.println("%");
  77.  
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement