# help w/ storing/scanning numbers in arrays(what am i doing wrong)

• 03-14-2011, 06:26 AM
clemsontigers
help w/ storing/scanning numbers in arrays(what am i doing wrong)
hey guys need some help w/ storing scanning numbers in arrarys

here are my instructions, code, and output

A Computer Technology Instructor has a small class of 10 students. The instructor evaluates the performance of students in the class by administering 2 midterm tests and a Final Exam.

Write a program that prompts the instructor to enter the 10 grades of midterm 1 and store these numbers in an array. Next prompt for the 10 grades of midterm 2 and store these numbers in a different array. Next prompt for the 10 grades of the Final Exam and store these in a different array. Next add midterm1 to midterm2 to Final and store the totals in a different array. Next, scan the array that has the totals and identify the minimum grade and maximum grade. Inform the instructor of the minimum grade and maximum grade.

Code:

``` import java.util.Scanner; import java.util.Arrays; public class Arrays {  public static void main(String[] args)     {         //input scanner         Scanner input = new Scanner(System.in);         //Prompt User for midterm1 grades         double[]midTerm1= new double [10];         for (int A = 0; A <midTerm1.length; A++){             System.out.println("Please enter MidTerm1 grade:");             midTerm1[A] = input.nextDouble();         }         System.out.println("Now");         //Prompt User for midterm2 grades         double[]midTerm2=new double[10];         for(int B=0; B<midTerm2.length;B++){             System.out.println("Please enter a MidTerm2 grade:");             midTerm2[B] = input.nextDouble();         }         System.out.println("Now");         //Prompt User for Final Exam grades         double[]finalExam = new double[10];         for(int C = 0; C<finalExam.length; C++){             System.out.println("Please enter a Final Exam grade:");             finalExam[C] = input.nextDouble();         }         int [] grades = new int [10];                 double max = 0;         double min = 0;         //Display highest score         for (int t = 0; t < grades.length; t ++)         {             if (grades[t] > max)             {  max = grades[t];             }                         //Display lowest score             if(grades[t] < min)             {                 min = grades[t];             }         }         System.out.print("Your highest test score is: " + max);         System.out.print("Your lowest test score is: " + min);         System.out.print("You have entered following grades for midTerm1:    ");         System.out.println(Arrays.toString(midTerm1));         System.out.print("You have entered following grades for midTerm2:    ");         System.out.println(Arrays.toString(midTerm2));         System.out.print("You have entered following grades for Final Exam:  ");         System.out.println(Arrays.toString(finalExam));             } }```
output(using eclipse btw)

Your highest test score is: 0.0Your lowest test score is: 0.0You have entered following grades for midTerm1: [1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 5.0, 67.0, 7.0, 5.0]
You have entered following grades for midTerm2: [5.0, 5.0, 7.0, 6.0, 54.0, 53.0, 3.0, 5.0, 4.0, 4.0]
You have entered following grades for Final Exam: [3.0, 4.0, 5.0, 6.0, 5.0, 47.0, 7.0, 7.0, 5.0, 4.0]
• 03-14-2011, 07:20 AM
subith86
as far as I see grades is only initialized... Nothing else is done on it.
Code:

`int [] grades = new int [10];`
All the 10 values will be zero.
Next you are running a for loop to find the max. It'll definitely be zero.
• 03-14-2011, 07:19 PM
clemsontigers
here is my updated code and output...i believe im heading in the right direction but i dont think it is calculating my min and max grade correctly

Code:

```import java.util.Scanner; import java.util.Arrays; public class Arrays { public static void main(String[] args) { //input scanner Scanner input = new Scanner(System.in); //Prompt User for midterm1 grades double[]midTerm1= new double [10]; for (int A = 0; A <midTerm1.length; A++){ System.out.println("Please enter MidTerm1 grade:"); midTerm1[A] = input.nextDouble(); } System.out.println("Now"); //Prompt User for midterm2 grades double[]midTerm2=new double[10]; for(int B=0; B<midTerm2.length;B++){ System.out.println("Please enter a MidTerm2 grade:"); midTerm2[B] = input.nextDouble(); } System.out.println("Now"); //Prompt User for Final Exam grades double[]finalExam = new double[10]; for(int C = 0; C<finalExam.length; C++){ System.out.println("Please enter a Final Exam grade:"); finalExam[C] = input.nextDouble(); } double [] grades = new double [10]; for (int i = 0; i < grades.length;i ++){ grades[i] = midTerm1[i] +midTerm2[i]+finalExam[i]; } double max = 0; double min = 0; max = grades[0]; for (int i=1; i<grades.length; i++) { if (grades[i] > max) { max = grades[i]; } } min = grades[0]; for (int i=1; i<grades.length; i++) { if (grades[i] < min) { min = grades[i]; } } System.out.print("Your highest test score is: " + max); System.out.print("Your lowest test score is: " + min); System.out.print("You have entered following grades for midTerm1:    "); System.out.println(Arrays.toString(midTerm1)); System.out.print("You have entered following grades for midTerm2:    "); System.out.println(Arrays.toString(midTerm2)); System.out.print("You have entered following grades for Final Exam:  "); System.out.println(Arrays.toString(finalExam)); } }```
and here is my output after entering the grades

Your highest test score is: 281.0Your lowest test score is: 198.0You have entered following grades for midTerm1: [89.0, 98.0, 78.0, 87.0, 56.0, 65.0, 45.0, 54.0, 88.0, 99.0]
You have entered following grades for midTerm2: [100.0, 78.0, 87.0, 98.0, 67.0, 87.0, 88.0, 99.0, 92.0, 94.0]
You have entered following grades for Final Exam: [90.0, 90.0, 88.0, 34.0, 75.0, 100.0, 99.0, 88.0, 77.0, 88.0]
• 03-15-2011, 04:20 AM
clemsontigers
can anyone confirm if i am right or not?
• 03-15-2011, 04:58 AM
subith86
everything looks fine according to me, except max score and min score.
What are they supposed to be? is it the max/min of all the terms or max/min of the total of all terms(grade). The second case is what you are getting now.