The book is : Starting Out with Java: From Control Structures through Objects (6th Edition) . It is follow by many computer sciences schools.
The example I have is from that book :
- However to improve my programming skills I try to always add a new feature in the program example which is the "age feature(average)
However in this program it seems that when I implement that age feature it's giving wrong results for the entire program (score age etc..)
- I try to add a second total1 and second ageAverage to avoid messing up with the score feature. Also I don't need an age average in each student
all I need is an age average after the end of the program which makes since. I tried to figure out that I could get a method outside
the for student loop but it will not work . Anyway here's the example of the book :
The program in Code Listing 4-13 shows another example. It is a program that a teacher
might use to get the average of each student’s test scores. In line 22 the user enters the num-
ber of students, and in line 26 the user enters the number of test scores per student. The for
loop that begins in line 29 iterates once for each student. The nested inner for loop, in lines
36 through 41, iterates once for each test score.
How many students do you have? 3 [Enter]
How many test scores per student? 3 [Enter]
Student number 1
Enter score 1: 100 [Enter]
Enter score 2: 95 [Enter]
Enter score 3: 90 [Enter]
The average for student number 1 is 95.0.
Student number 2
Enter score 1: 80 [Enter]
Enter score 2: 81 [Enter]
Enter score 3: 82 [Enter]
The average for student number 2 is 81.0.
Student number 3
Enter score 1: 75 [Enter]
Enter score 2: 85 [Enter]
Enter score 3: 80 [Enter]
The average for student number 3 is 80.0.