# help w/ storing/scanning numbers in two dimensional arrays

• 12-01-2010, 02:29 AM
clemsontigers
help w/ storing/scanning numbers in two dimensional arrays
have a assignment that we have to accomplish the same work as in a previous assignment except use two dimensional arrays... this is my previous assignment

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 Midterm2 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 total of grades 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.

Note : do not assume that the grades are in the range 0 to 100. Your program should function properly whether the grades are in the range 0 to 100 or any other range.

*****and this is my next assignments instructions

Use one two-dimensional array to accomplish the same work you did in the last Assignment. Think of the students as being the columns of the two-dimensional array. Think of the scores of Midterm 1 as occupying the first row, scores of Midterm 2 occupying the next row, scores of the Final Exam occupying the next row. The total of the 3 exams occupying the next row. Inform the instructor of the minimum total grade and the maximum total grade.

***and here is my code, got errors all over the place and not sure where to begin or iif im even in the ballpark

Code:

``` import java.util.Scanner; import java.io.*; public class Assign10_Roberts{         public static void main(String[] args){ //input Scanner Scanner input=new Scanner(System.in); int midTerm1=0; int midTerm2=0; int finalExam=0; int[][]grades= new int[10][10]; System.out.println("Enter the 10 Midterm 1 grades: "); for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length ; j++){ System.out.println("MidTerm1 Grades "+(i+1)+": "); grades[i][j]=input.nextInt(); } System.out.print("Enter the 10 Midterm 2 grades: "); for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Midterm2 Grades "+(i+1)+": "); grades[i][j]=input.nextInt(); } System.out.print("Enter the 10 Final Exam grades: "); for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Final Exam Grade "+(i+1)+": "); grades[i][j]=input.nextInt(); } for (int i=0;i<10;i++) grades[i]=midterm1[i]+midterm2[i]+finalExam int minGrade=grades[0]; int maxGrade=grades[0]; for (int i=1;i<10;i++) { if (minGrade>grades[i]) minGrade=grades[i]; if (maxGrade<grades[i]) maxGrade=grades[i]; } System.out.println("The minimum grade is "+minGrade); System.out.println("The maximum grade is "+maxGrade); } } }```
also this is cross posted, thanks
http://www.javaprogrammingforums.com...html#post22064
• 12-01-2010, 02:54 AM
Zack
What are the full error message contents?
• 12-01-2010, 02:59 AM
clemsontigers
everything underlined as well as some of the i's and j's
Code:

```for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Midterm2 Grades "+(i+1)+": "); grades[i][j]=input.nextInt(); } System.out.print("Enter the 10 Final Exam grades: "); for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Final Exam Grade "+(i+1)+": "); grades[i][j]=input.nextInt(); } for (int i=0;i<10;i++) grades[i]=[U]midterm1[i]+midterm2[i]+finalExam[/U] [U]int minGrade=grades[0]; int maxGrade=grades[0]; [/U] for (int i=1;i<10;i++) { if ([U]minGrade>grades[i][/U]) minGrade=grades[i]; if ([U]maxGrade<grades[i])[/U] maxGrade=grades[i]; }```
• 12-01-2010, 05:15 AM
Zack
No. The actual error messages.

Something like this, if it's a runtime error:
Code:

```java.lang.NumberFormatException: For input string: "c"         at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)         at java.lang.Integer.parseInt(Integer.java:449)         at java.lang.Integer.parseInt(Integer.java:499)         at base.base.<init>(base.java:17)```

Or something like this if it's compile-time:
Code:

`(line 20, base.java) missing method body, or declare abstract`
• 12-01-2010, 06:34 AM
clemsontigers
oh oops...heres the error im gettin

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Duplicate local variable i
j cannot be resolved to a variable
Duplicate local variable i
j cannot be resolved to a variable
Duplicate local variable i
midterm1 cannot be resolved to a variable
midterm2 cannot be resolved to a variable
Syntax error, insert ";" to complete Statement
Type mismatch: cannot convert from int[] to int
Type mismatch: cannot convert from int[] to int
Duplicate local variable i
The operator > is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int

at Assign10_Roberts.main(Assign10_Roberts.java:39)
• 12-01-2010, 07:31 AM
mine0926
Notice the bold for loop, I tink you forgot to put opening ang closing braces ("{}").
Code:

```for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Midterm2 Grades "+(i+1)+": "); grades[i][j]=input.nextInt(); } System.out.print("Enter the 10 Final Exam grades: "); for (int i = 0; i < grades.length; i++){ for (int j = 0; j < grades.length; j++) System.out.print("Final Exam Grade "+(i+1)+": "); grades[i][j]=input.nextInt(); } [b] for (int i=0;i<10;i++) grades[i]=midterm1[i]+midterm2[i]+finalExam int minGrade=grades[0]; int maxGrade=grades[0]; [/b] for (int i=1;i<10;i++) { if (minGrade>grades[i]) minGrade=grades[i]; if (maxGrade<grades[i]) maxGrade=grades[i]; }```
• 12-01-2010, 07:49 AM
mine0926
I have something that I want you to see.

Quote:

Both dimension are declared 10.

in 2d array, the first array is the ROW and the second array is column
Code:

`int[][]grades= new int[this is ROW][this is column];`
Your teacher told you to have
• Midterm1 as first row
• Midterm2 as next row
• FinalExam as next row
• Total of three(3) exams as next row
• 12-01-2010, 06:42 PM
clemsontigers
ok here is my updated code

Code:

```import java.util.Scanner; import java.io.*; public class Assign10_Roberts{         public static void main(String[] args){ //input Scanner Scanner input=new Scanner(System.in); int midTerm1=0; int midTerm2=0; int finalExam=0; int[][]grades= new int[10][10]; for(int i=0; i<10; i++) { // Midterm 1 grades[i][0]=input.nextInt(); } for(int i=0; i<10; i++) { // Midterm 2 grades[i][1]=input.nextInt(); } for(int i=0; i<10; i++) { // Final Exam grades[i][2]=input.nextInt(); System.out.println("Enter the 10 Midterm 1 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Midterm 2 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Final Exam grades: "); grades[i][j]=input.nextInt(); } {         if (minGrade>grades[i]) minGrade=grades[i]; if (maxGrade<grades[i]) maxGrade=grades[i]; } System.out.println("The minimum grade is "+minGrade); System.out.println("The maximum grade is "+maxGrade); } }```
and this is the error im getting
• 12-02-2010, 01:13 AM
mine0926
and what error do you get?
• 12-02-2010, 01:51 AM
clemsontigers
sorry i thought it pasted along w/ the rest...here is my errors

minGrade cannot be resolved to a variable
maxGrade cannot be resolved to a variable

at Assign10_Roberts.main(Assign10_Roberts.java:39
• 12-02-2010, 02:04 AM
clemsontigers
here is my updated code and errors

Code:

```public class Assign10_Roberts{         public static void main(String[] args){ //input Scanner Scanner input=new Scanner(System.in); int midTerm1=0; int midTerm2=0; int finalExam=0; int minGrade = 0; int maxGrade = 0; int[][]grades= new int[9][9]; for(int i=0, j=0; i<10; i++) { // Midterm 1 grades[i][0]=input.nextInt(); } for(int i=0; i<10; i++) { // Midterm 2 grades[i][1]=input.nextInt(); } for(int i=0, j=0; i<10; i++) { // Final Exam grades[i][2]=input.nextInt(); System.out.println("Enter the 10 Midterm 1 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Midterm 2 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Final Exam grades: "); grades[i][j]=input.nextInt();                 if (minGrade>grades[i]) minGrade=grades[i]; if (maxGrade<grades[i]) maxGrade=grades[i]; } System.out.println("The minimum grade is " + minGrade); System.out.println("The maximum grade is "+ maxGrade); } }```
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The operator > is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int
The operator < is undefined for the argument type(s) int, int[]
Type mismatch: cannot convert from int[] to int

at Assign10_Roberts.main(Assign10_Roberts.java:49)
• 12-02-2010, 02:11 AM
mine0926
I think you did not declare minGrade and maxGrade
Code:

```     int minGrade = grades[0][0];     int maxGrade = grades[0][0];```
• 12-02-2010, 02:16 AM
mine0926
You declare grades as 2D array.
Code:

`int[][]grades= new int[10][10];`
Threfore, when getting or setting value to grades you ALWAYS need to put the arrays.
Code:

` grades[array/row][array/column]`
See the code in bold letters
Quote:

Originally Posted by clemsontigers
here is my updated code and errors

Code:

```public class Assign10_Roberts{         public static void main(String[] args){ //input Scanner Scanner input=new Scanner(System.in); int midTerm1=0; int midTerm2=0; int finalExam=0; int minGrade = 0; int maxGrade = 0; int[][]grades= new int[9][9]; for(int i=0, j=0; i<10; i++) { // Midterm 1 grades[i][0]=input.nextInt(); } for(int i=0; i<10; i++) { // Midterm 2 grades[i][1]=input.nextInt(); } for(int i=0, j=0; i<10; i++) { // Final Exam grades[i][2]=input.nextInt(); System.out.println("Enter the 10 Midterm 1 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Midterm 2 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Final Exam grades: "); grades[i][j]=input.nextInt();                 if (minGrade>[b]grades[i][/b]) minGrade=[b]grades[i][/b]; if (maxGrade<[b]grades[i][/b]) maxGrade=[b]grades[i][/b]; } System.out.println("The minimum grade is " + minGrade); System.out.println("The maximum grade is "+ maxGrade); } }```

• 12-02-2010, 02:38 AM
clemsontigers
not sure is this is any better here is what i changed

Code:

```import java.util.Scanner; import java.io.*; public class Assign10_Roberts{         public static void main(String[] args){ //input Scanner Scanner input=new Scanner(System.in); int midTerm1=0; int midTerm2=0; int finalExam=0; int[][]grades= new int[10][10]; for(int i=0, j=0; i<10; i++) { // Midterm 1 grades[i][0]=input.nextInt(); } for(int i=0; i<10; i++) { // Midterm 2 grades[i][1]=input.nextInt(); } for(int i=0, j=0; i<10; i++) { // Final Exam grades[i][2]=input.nextInt(); System.out.println("Enter the 10 Midterm 1 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Midterm 2 grades: "); grades[i][j]=input.nextInt(); System.out.print("Enter the 10 Final Exam grades: "); grades[i][j]=input.nextInt(); {         public static double getCurrentMin (double [][] input) {                    double minGrade = input[0][0];             double maxGrade = input[0][0];         for (int row = 0; row < input.length; row++){             for (int column = 0; column < input [row].length; column++){                 if (minGrade = > input[row][column]){                     minGrade = input[row][column];                 }             }         public static double getCurrentMax (double [][] input){        double minGrade = input[0][0];     double maxGrade = input[0][0];     for (int row = 0; row < input.length; row++){         for (int column = 0; column < input [row].length; column++){             if (maxGrade < input[row][column]){                 maxGrade = input[row][column];        System.out.println("The minimum grade is " + minGrade); System.out.println("The maximum grade is "+ maxGrade); } } } } }```
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error, insert "}" to complete Block
Syntax error, insert "}" to complete Block
Syntax error, insert "}" to complete MethodBody

at Assign10_Roberts.main(Assign10_Roberts.java:44)
• 12-02-2010, 03:06 AM
mine0926
I would suggest that you start from scratch and follow what your teacher and members of both forums instructed/suggested you.
Also, use proper indention to properly and easily debug opening and closing braces.

The code you are showing has lots of error (compile, runtime and logical error) and far from the intruction gave to you.

Please dont get me wrong, and dont think that you will not be able to do this. I was just thinking that it will be easier for you
to understand these if you start from scratch and we are willing to help you here.
• 12-02-2010, 03:08 AM
mine0926
Here is your code if proper indention is used.
Code:

```import java.util.Scanner; import java.io.*; public class TrialONLY{     public static void main(String[] args)     {         //input Scanner         Scanner input=new Scanner(System.in);         int midTerm1=0;         int midTerm2=0;         int finalExam=0;                 int[][]grades= new int[10][10];         for(int i=0, j=0; i<10; i++)         {             // Midterm 1             grades[i][0]=input.nextInt();         }         for(int i=0; i<10; i++)         {             // Midterm 2             grades[i][1]=input.nextInt();         }         for(int i=0, j=0; i<10; i++)         {             // Final Exam             grades[i][2]=input.nextInt();             System.out.println("Enter the 10 Midterm 1 grades: ");             grades[i][j]=input.nextInt();             System.out.print("Enter the 10 Midterm 2 grades: ");             grades[i][j]=input.nextInt();             System.out.print("Enter the 10 Final Exam grades: ");             grades[i][j]=input.nextInt();             {  //<--------- What this doing?                 public static double getCurrentMin (double [][] input)                 {                     double minGrade = input[0][0];                     double maxGrade = input[0][0];                     for (int row = 0; row < input.length; row++)                     {                         for (int column = 0; column < input [row].length; column++)                         {                             if (minGrade = > input[row][column])                             {  minGrade = input[row][column];                             }                         }                                                 public static double getCurrentMax (double [][] input)                         {                             double minGrade = input[0][0];                             double maxGrade = input[0][0];                             for (int row = 0; row < input.length; row++)                             {                                 for (int column = 0; column < input [row].length; column++)                                 {                                     if (maxGrade < input[row][column])                                     {                                         maxGrade = input[row][column];                                         System.out.println("The minimum grade is " + minGrade);                                         System.out.println("The maximum grade is "+ maxGrade);                                     }                                 }                             }                         }                     }```