Results 1 to 16 of 16
  1. #1
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default 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

    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];
    
    
    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
    Last edited by clemsontigers; 12-01-2010 at 02:32 AM.

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    What are the full error message contents?

  3. #3
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    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];
    
    }

  4. #4
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    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

  5. #5
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    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)

  6. #6
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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];
    
    }

  7. #7
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I have something that I want you to see.

    int[][]grades= new int[10][10];
    Both dimension are declared 10.

    in 2d array, the first array is the ROW and the second array is column
    Java 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

  8. #8
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    ok here is my updated code

    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; 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

  9. #9
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    and what error do you get?

  10. #10
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    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

  11. #11
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    here is my updated code and errors

    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);
    
    }
    
    }
    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. #12
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    I think you did not declare minGrade and maxGrade
    Java Code:
     
        int minGrade = grades[0][0];
        int maxGrade = grades[0][0];

  13. #13
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    You declare grades as 2D array.
    Java Code:
    int[][]grades= new int[10][10];
    Threfore, when getting or setting value to grades you ALWAYS need to put the arrays.
    Java Code:
     grades[array/row][array/column]
    See the code in bold letters
    Quote Originally Posted by clemsontigers View Post
    here is my updated code and errors

    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>[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);
    
    }
    
    }
    Last edited by mine0926; 12-02-2010 at 02:21 AM.

  14. #14
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default

    not sure is this is any better here is what i changed

    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);
    
    }
    
    }
    
    }
    
    }
    
    }
    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)

  15. #15
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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.

  16. #16
    mine0926 is offline Senior Member
    Join Date
    Apr 2010
    Location
    Philippines
    Posts
    580
    Rep Power
    5

    Default

    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

  1. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 11-18-2010, 06:12 AM
  2. two dimensional arrays
    By cliffh in forum New To Java
    Replies: 2
    Last Post: 11-06-2010, 12:43 AM
  3. dynamic two dimensional arrays?
    By dinosoep in forum New To Java
    Replies: 4
    Last Post: 12-05-2009, 07:12 PM
  4. Multi-dimensional arrays
    By Implode in forum New To Java
    Replies: 1
    Last Post: 09-15-2009, 09:50 AM
  5. Adding numbers in a 2 dimensional array
    By j0shizabeast in forum New To Java
    Replies: 2
    Last Post: 11-27-2007, 05:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •