Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void avgGroupChange() throws IOException
- {
- System.out.println( "Enter file name: " );
- String filename = scan.nextLine().trim();
- File file = new File( filename );
- Scanner scan2 = new Scanner( file );
- int groups = scan2.nextInt();
- int currentGroup = 0;
- int groupSize = 0;
- int start, end;
- while ( scan2.hasNextLine() )
- {
- int groupSize = scan2.nextInt();
- currentGroup++;
- int startSum;
- int endSum;
- for(int i = 0; i < groupSize; i++) {
- start = scan2.nextInt();
- end = scan2.nextInt();
- startSum += start;
- endSum += end;
- }
- if(groupSize > 0) {
- double startAvg = (startSum / groupSize);
- double endAvg = (endSum / groupSize);
- }
- System.out.println( "Group" + currentGroup + '\t' + groupSize + "subjects" );
- System.out.println( "average starting cholesterol:" + '\t'
- + startAvg );
- System.out.println( "average final cholesterol:" + '\t'
- + endAvg );
- System.out.println( "change in cholesterol:" + '\t' + (endAvg - startAvg) );
- }
- System.out.println( "Done with processing." );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement