Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.File;
- public class SodaSales {
- public static void main(String []args)throws Exception {
- File file = new File("D:\\Eclipse\\mcc\\src\\csc161\\sodasales.dat");
- Scanner input = new Scanner(file);
- int index = 0;
- String[] brandArray = new String[5];
- int[] bottleSoldArray = new int [5];
- double[] bottleCostArray = new double [5];
- double[] bottleRetailArray = new double [5];
- System.out.println(" Soda Sales");
- System.out.println("");
- System.out.println(" Bottles Cost Retail Profit Percent");
- System.out.println("Soda Sold Bottle Bottle Brand Sold of 150");
- System.out.println("---- ---- ------ ------ ------ ---------");
- int totalBottles = 0;
- float totalProfit = 0;
- float totalCost = 0;
- float totalRetail = 0;
- int brandTotal = 0;
- while (input.hasNext()) {
- String brand = input.next();
- while(!input.hasNextInt() && !input.hasNextFloat()){
- brand = brand + " " + input.next();
- brandTotal++;
- }
- int bottles = input.nextInt();
- float cost = input.nextFloat();
- float retail = input.nextFloat();
- float profit = (float)bottles * (retail - cost);
- totalBottles += bottles;
- totalCost += cost;
- totalRetail += retail;
- totalProfit += profit;
- brandArray[index] = brand;
- bottleSoldArray[index] = bottles;
- bottleCostArray[index] = cost;
- bottleRetailArray[index] = retail;
- printInfo(brand, bottles, cost, retail, profit);
- index++;
- }
- System.out.print("Totals ");
- System.out.print(totalBottles);
- System.out.print(" ");
- System.out.printf("%.2f", ((float)totalCost/brandTotal));
- System.out.print(" ");
- System.out.printf("%.2f", ((float)totalRetail/brandTotal));
- System.out.println(" " + totalProfit);
- input.close();
- }
- public static void printInfo(String brand, int bottles, float cost, float retail, float profit) {
- System.out.print(brand);
- System.out.print(" " + bottles + " ");
- System.out.printf("%.2f", + cost);
- System.out.print(" ");
- System.out.printf("%.2f",+ retail);
- System.out.print(" ");
- System.out.printf("%.2f",+ (float)profit);
- System.out.print(" ");
- System.out.printf("%.2f",+ (float)((float)bottles/150*100));
- System.out.println("%");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement