Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- 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];
- String[] sortedBrandArray = new String[5];
- int[] sortedBottleArray = new int [5];
- double[] sortedBottleCost = new double [5];
- double[] sortedRetailCost = 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();//setting conditions to grab input with spaces AK
- brandTotal++; //adding to the total number of brands there are AK
- }
- 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;
- // for (int i = 0; i < brandArray.length - 1; i++) {
- // String a = brandArray[i];
- // String b = brandArray[i+1];
- //
- // if (a.compareTo(b)>0){
- // String temp = brandArray[i];
- // brandArray[i] = brandArray[i+1];
- // brandArray[i+1] = temp;
- // }
- //
- //
- // }
- //printInfo(brand, bottles, cost, retail, profit);
- index++;
- }
- sortedBrandArray = brandArray;
- sortedBottleArray = bottleSoldArray;
- Arrays.sort(sortedBrandArray);
- String sodaName = "";
- for (int i = 0; i < brandArray.length; i++)
- {
- sodaName = sortedBrandArray[i];
- for(int j = 0; j < brandArray.length; j++){
- if (brandArray[j].equals(sodaName))
- {
- index = j;
- System.out.print(sortedBrandArray[index]);
- System.out.print(" " + bottleSoldArray[index] + " ");
- System.out.printf("%.2f", + bottleCostArray[index]);
- System.out.print(" ");
- System.out.printf("%.2f", + bottleRetailArray[index]);
- System.out.print(" ");
- System.out.printf("%.2f",+ (float)(bottleRetailArray[index] * bottleSoldArray[index]) -
- (bottleCostArray[index]*bottleSoldArray[index]));
- System.out.print(" ");
- System.out.printf("%.2f",+ (float)((float)bottleSoldArray[index]/150*100));
- System.out.println("%");
- break;
- }
- }
- }
- 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();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement