Advertisement
Guest User

Untitled

a guest
Nov 25th, 2014
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 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 groupSize1 = scan2.nextInt();
  16.             currentGroup++;
  17.             int startSum = 0;
  18.             int endSum = 0;
  19.             for ( int i = 0; i < groupSize1; i++ )
  20.             {
  21.                 start = scan2.nextInt();
  22.                 end = scan2.nextInt();
  23.                 startSum += start;
  24.                 endSum += end;
  25.             }
  26.             double startAvg = ( startSum / groupSize1 );
  27.             double endAvg = ( endSum / groupSize1 );
  28.             System.out.println( "Group" + currentGroup + '\t' + groupSize1
  29.                 + "subjects" );
  30.             System.out.println( "average starting cholesterol:" + '\t'
  31.                 + startAvg );
  32.             System.out.println( "average final  cholesterol:" + '\t' + endAvg );
  33.             System.out.println( "change in cholesterol:" + '\t'
  34.                 + ( endAvg - startAvg ) );
  35.         }
  36.         System.out.println( "Done with processing." );
  37.  
  38.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement