File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
src/org/launchcode/java/demos/collections Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ package org .launchcode .java .demos .collections ;
2+
3+ import java .util .ArrayList ;
4+ import java .util .Scanner ;
5+
6+ public class Gradebook {
7+
8+ public static void main (String [] args ) {
9+
10+ ArrayList <String > students = new ArrayList <>();
11+ ArrayList <Double > grades = new ArrayList <>();
12+ Scanner in = new Scanner (System .in );
13+ String newStudent ;
14+
15+ System .out .println ("Enter your students (or ENTER to finish):" );
16+
17+ // Get student names
18+ do {
19+ newStudent = in .nextLine ();
20+
21+ if (!newStudent .equals ("" )) {
22+ students .add (newStudent );
23+ }
24+
25+ } while (!newStudent .equals ("" ));
26+
27+ // Get student grades
28+ for (String student : students ) {
29+ System .out .print ("Grade for " + student + ": " );
30+ Double grade = in .nextDouble ();
31+ grades .add (grade );
32+ }
33+
34+ // Print class roster
35+ System .out .println ("\n Class roster:" );
36+ double sum = 0.0 ;
37+
38+ for (int i = 0 ; i < students .size (); i ++) {
39+ System .out .println (students .get (i ) + " (" + grades .get (i ) + ")" );
40+ sum += grades .get (i );
41+ }
42+
43+ double avg = sum / students .size ();
44+ System .out .println ("Average grade: " + avg );
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments