Advertisement
Arush22

Untitled

May 7th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. package Suarez;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.util.Scanner;
  5. public class AveragePrice {
  6. public static void main(String[] args) throws IOException {
  7. File fileInput = new File("C:\\Users\\Arush\\IdeaProjects\\9th Grade Tri2\\src\\Suarez\\Prices");
  8. Scanner input = new Scanner(fileInput);
  9. while(input.hasNextLine()){
  10. String line = input.nextLine();
  11. Scanner lineBreaker = new Scanner(line);
  12. String product = lineBreaker.next();
  13. double total = 0;
  14. int count = 0;
  15. while (lineBreaker.hasNextDouble()){
  16. total = total = total + lineBreaker.nextDouble();
  17. count++;
  18. }
  19. System.out.println(line+" Average: " + total/count);
  20. }
  21.  
  22. }
  23. }
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. PRICES:
  36. coffee 10.00 20.00 30.00
  37. coke 11.00 12.00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement