Results 1 to 16 of 16
- 12-01-2010, 01:29 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
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
also this is cross posted, thanksJava 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); } } }
http://www.javaprogrammingforums.com...html#post22064Last edited by clemsontigers; 12-01-2010 at 01:32 AM.
- 12-01-2010, 01:54 AM #2
- 12-01-2010, 01:59 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
everything underlined as well as some of the i's and j's
Java 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, 04:15 AM #4
No. The actual error messages.
Something like this, if it's a runtime error:
Java 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:
Java Code:(line 20, base.java) missing method body, or declare abstract
- 12-01-2010, 05:34 AM #5
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
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, 06:31 AM #6
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Notice the bold for loop, I tink you forgot to put opening ang closing braces ("{}").
Java 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, 06:49 AM #7
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
I have something that I want you to see.
Both dimension are declared 10.int[][]grades= new int[10][10];
in 2d array, the first array is the ROW and the second array is column
Your teacher told you to haveJava Code:int[][]grades= new int[this is ROW][this is column];
- Midterm1 as first row
- Midterm2 as next row
- FinalExam as next row
- Total of three(3) exams as next row
- 12-01-2010, 05:42 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
ok here is my updated code
and this is the error im gettingJava 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); } }
- 12-02-2010, 12:13 AM #9
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
and what error do you get?
- 12-02-2010, 12:51 AM #10
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
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, 01:04 AM #11
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
here is my updated code and errors
Exception in thread "main" java.lang.Error: Unresolved compilation problems:Java 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); } }
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, 01:11 AM #12
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
I think you did not declare minGrade and maxGrade
Java Code:int minGrade = grades[0][0]; int maxGrade = grades[0][0];
- 12-02-2010, 01:16 AM #13
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Last edited by mine0926; 12-02-2010 at 01:21 AM.
- 12-02-2010, 01:38 AM #14
Member
- Join Date
- Oct 2010
- Posts
- 44
- Rep Power
- 0
not sure is this is any better here is what i changed
Exception in thread "main" java.lang.Error: Unresolved compilation problems:Java 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); } } } } }
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, 02:06 AM #15
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
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, 02:08 AM #16
Senior Member
- Join Date
- Apr 2010
- Location
- Philippines
- Posts
- 580
- Rep Power
- 4
Here is your code if proper indention is used.
Java 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); } } } } }
Similar Threads
-
help w/ storing/scanning numbers in arrays
By clemsontigers in forum New To JavaReplies: 15Last Post: 11-18-2010, 05:12 AM -
two dimensional arrays
By cliffh in forum New To JavaReplies: 2Last Post: 11-05-2010, 11:43 PM -
dynamic two dimensional arrays?
By dinosoep in forum New To JavaReplies: 4Last Post: 12-05-2009, 06:12 PM -
Multi-dimensional arrays
By Implode in forum New To JavaReplies: 1Last Post: 09-15-2009, 08:50 AM -
Adding numbers in a 2 dimensional array
By j0shizabeast in forum New To JavaReplies: 2Last Post: 11-27-2007, 04:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks