Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. public void avgGroupChange() throws IOException
  2. {
  3. System.out.println( "Enter file name: " );
  4. String filename = scan.nextLine().trim();
  5. File file = new File( filename );
  6. Scanner scan2 = new Scanner( file );
  7.  
  8. int groups = scan2.nextInt();
  9. int currentGroup = 0;
  10. int groupSize = 0;
  11. int start, end;
  12.  
  13. while ( scan2.hasNextLine() )
  14. {
  15. int groupSize = scan2.nextInt();
  16. currentGroup++;
  17. int startSum;
  18. int endSum;
  19. for(int i = 0; i < groupSize; i++) {
  20. start = scan2.nextInt();
  21. end = scan2.nextInt();
  22. startSum += start;
  23. endSum += end;
  24. }
  25. if(groupSize > 0) {
  26. double startAvg = (startSum / groupSize);
  27. double endAvg = (endSum / groupSize);
  28. }
  29. System.out.println( "Group" + currentGroup + '\t' + groupSize + "subjects" );
  30. System.out.println( "average starting cholesterol:" + '\t'
  31. + startAvg );
  32. System.out.println( "average final cholesterol:" + '\t'
  33. + endAvg );
  34. System.out.println( "change in cholesterol:" + '\t' + (endAvg - startAvg) );
  35. }
  36. System.out.println( "Done with processing." );
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement