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

    Default 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.



    Java 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]

  2. #2
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default

    as far as I see grades is only initialized... Nothing else is done on it.
    Java 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.

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

    Default

    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

    Java 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]

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

    Default

    can anyone confirm if i am right or not?

  5. #5
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Default

    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.

Similar Threads

  1. Storing Inputs in Two Linked Arrays
    By essence388 in forum New To Java
    Replies: 1
    Last Post: 12-26-2010, 02:21 PM
  2. help w/ storing/scanning numbers in two dimensional arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 12-02-2010, 02:08 AM
  3. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 11-18-2010, 05:12 AM
  4. Need help storing arrays from a file
    By arson09 in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 04:11 PM
  5. Storing and managing huge arrays
    By trust in forum Java Software
    Replies: 2
    Last Post: 08-22-2009, 02:47 PM

Posting Permissions

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