Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    need help wtih this code!

    been working on some java on day and cant think straight anymore..maybe someone can look at this and help me out

    Code:
    import java.util.*;
    
    public class lab3{
    public static void main(String[] args) throws Exception  {
    java.io.File file = new java.io.File("CPS2231Lab3.data");
    
    Scanner input = new Scanner(file);
    
    //Declare Variables
    
    
    int ArraySize = input.nextInt();                // READ ARRAY SIZE
    int[][] TestScore = new int[ArraySize][3];      // DEFINE ARRAY
    
    
    System.out.print("Student\t\t   Exam1\t   Exam2\t   Exam3\t    Avg \n");
    System.out.println("---------\t---------\t---------\t---------\t--------\n");
    
       // PRINT ARRAY
    
    for (int i = 0; i<TestScore.length; i++) {
    for (int j = 0; j<TestScore[i].length; j++) {
    TestScore[i][j]=input.nextInt();
    
    }
     }
    
    double HighAvg=0.0;
                                                    // HIGH
    int highest[]= new int [3];
    for (int i=0;i<TestScore.length;i++){
    for (int j=0;j<3;j++) {
    
    if (highest[j]< TestScore[i][j]) {
     highest[j] = TestScore[i][j];
    // int temp = highest[j];
    //System.out.print(highest[j] + "  ");
    } // end if
    } // end [i]
    }
    
    
    //System.out.print(HighAvg/4);
                                                    // LOW
    int lowest[]=new int[3];
    lowest[0]=100;
    lowest[1]=100;
    lowest[2]=100;
    
    for (int i=0;i<TestScore.length;i++) {
    for (int j=0;j<3;j++) {
    
    if (lowest[j]>TestScore[i][j]){
    lowest[j]=TestScore[i][j];
    }
    }
    }
    
    
    // DECLARE STUDENT
    int Student=0;
                                                    // AVERAGE
    System.out.println("");
    for (int i=0; i<TestScore.length;i++) {
            double TotalAvg=0.0;                            //finds average
            System.out.print(i+1);
            System.out.print("\t\t");
    
            for (int j=0;j<TestScore[i].length;j++) {
                    System.out.print(TestScore[i][j]);
                    System.out.print("\t\t");
                    TotalAvg=(TestScore[i][0] + TestScore[i][1] +
    TestScore[i][3]) / 3;
    
    
            }
            System.out.print(TotalAvg+"\n");
    }
    
    System.out.println("");                                //finds and prints lowest
    System.out.print("Lowest :      ");
    for (int i=0;i<lowest.length;i++){
    System.out.print(lowest[i]);
    System.out.print("\t\t");
    
    }
    
    System.out.println("");
    
    System.out.print("Highest :     ");                      //finds and prints highest
    for (int i=0;i< highest.length;i++) {
       System.out.print(highest[i]);
    System.out.print("\t\t");
    HighAvg=HighAvg+highest[i];
    
    }
    
    System.out.println();
    
    }// end class
            }// end

  • #2
    Gox
    Gox is offline
    Regular Coder Gox's Avatar
    Join Date
    May 2006
    Location
    Ontario, Canada
    Posts
    392
    Thanks
    2
    Thanked 20 Times in 20 Posts
    What's your issue?...What is it suppose to do? What doesn't it do properly? What are the requirements of Lab3?

    Providing this type of information will help.


  •  

    Posting Permissions

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