Results 1 to 7 of 7
  1. #1
    Mekulaventure is offline Member
    Join Date
    Nov 2015
    Posts
    3
    Rep Power
    0

    Default How can is solve this?

    please can anyone help me with this as I don't know how to go about it.
    Write a program that calculates the total average of each student in a class along with his/her
    letter grade and then displays information about the student with the highest score and the
    student with the lowest score and displays the list of all the students along with their exam
    scores, their total average and their corresponding letter grade. The program should also output
    the average of each test and the final average of the class.
    Assume ten students in the class, declare the following inputs:
    1- An array that holds the last names of the students.
    2- An array to hold the first names of the students.
    3- An Array for the grades of Test 1 for each student.
    4- An Array for the grades of Test 2 for each student.
    5- An Array for the final exam grades for each student.
    To calculate the letter grades:
    1- First write a method the finds the total average of each student assuming the weight for
    the final exam is 45%, and a weight of 25 % for the minimum grade between tests 1 and
    2 and 30% for the test with the higher grades between Tests 1 and 2.
    2- Based on the total average, write a method that finds the letter grade as follows:
    i. A if 90<= Total Average <=100.
    ii. B if 80<= Total Average <90.
    iii. C if 70<= Total Average <80.
    iv. D if 60<= Total Average <70.
    v. F if Total Average <60.
    To display the required output:
    1- Write a method that calculates and displays the averages for Test 1, Test 2 and the Final
    Exam as well as the class average.
    2- Write a method that finds the student with the highest average and displays the
    information about the student in the following order:
    Last name, First name, Test 1 score, Test 2 Score, Final Exam score, Total average, Letter grade.
    3- Write a method that finds the student with the lowest average and displays the
    information about the student in the following order:
    Last name, First name, Test 1 score, Test 2 Score, Final Exam score, Total average, Letter grade
    4- Write a method that displays the information about all the students in the form:
    Last name, First name, Test 1 score, Test 2 Score, Final Exam score, Total average, Letter grade.
    Use the following table as your input
    LastName Firstname Test1 Test2 FinalExam
    Sal1 Has1 96 73 85
    Sal2 Has2 73 89 69
    Sal3 Has3 89 70 71
    Sal4 Has4 83 63 30
    Sal5 Has5 31 52 50
    Sal6 Has6 77 87 94
    Sal7 Has7 92 61 80
    Sal8 Has8 87 83 91
    Sal9 Has9 85 94 72
    Sal10 Has10 45 97 67

    please what I have done so far;

    public class InitializeArray {

    public static void main(String[]args){
    String [] LastName = {"Sal1","Sal2","Sal3","Sal4","Sal5","Sal6","Sal7", "Sal8","Sal9","Sal10"};
    String [] FirstName = {"Has1","Has2","Has3","Has4","Has5","Has6","Has7", "Has8","Has9","Has10"};
    int [] Test1 = {96,73,89,83,31,77,92,87,85,45};
    int [] Test2 = {73,89,70,63,52,87,61,83,94,97};
    int [] FinalExam = {85,69,71,30,50,94,80,91,72,67};
    System.out.println("LastName FirstName Test1 Test2 FinalExam TotalAverage");
    System.out.println("============================== ================================");
    for (int i = 0; i<10;i++) {
    System.out.printf("%s\t\t%s\t%d\t%d\t%d\t%f\n",Las tName[i],FirstName[i],Test1[i],Test2[i],FinalExam[i],TotalAverage (Test1,Test2,FinalExam));
    }

    }

    public static double TotalAverage(int Test1[], int Test2[],int FinalExam[]) {
    double TotalAverage;
    // TODO Auto-generated method stub
    int i =0;

    for (i=0; i<10;i++){
    if (Test1[i] < Test2[i]){
    TotalAverage = ((0.45*FinalExam[i]) + (0.25*Test1[i]) + (0.3*Test2[i]));
    return TotalAverage;
    }

    else if (Test1[i]>Test2[i]){
    TotalAverage = ((0.45*FinalExam[i]) + (0.3*Test1[i]) + (0.25*Test2[i]));

    return TotalAverage;


    }



    }



    }
    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How can is solve this?

    Please edit you post and wrap the code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default Re: How can is solve this?

    Hey i was able to fix your errors. Compare what I have to what you have. I would recommend getting into indenting your code so it can become easier to read. Also brush up on how to pass arrays as a parameter in methods and don't for get to initialize a variable before using it in a loop. Hope you found this helpful.

    Java Code:
    public class InitializeArray {
        public static void main(String[]args){
          String [] LastName = {"Sal1","Sal2","Sal3","Sal4","Sal5","Sal6","Sal7", "Sal8","Sal9","Sal10"};
           String [] FirstName = {"Has1","Has2","Has3","Has4","Has5","Has6","Has7", "Has8","Has9","Has10"};
          int [] Test1 = {96,73,89,83,31,77,92,87,85,45};
          int [] Test2 = {73,89,70,63,52,87,61,83,94,97};
          int [] FinalExam = {85,69,71,30,50,94,80,91,72,67};
          System.out.println("LastName FirstName Test1 Test2 FinalExam TotalAverage");
          System.out.println("============================== ================================");
          for (int i = 0; i<10;i++) {
             System.out.printf("%s\t\t%s\t%d\t%d\t%d\t%f\n",LastName[i],FirstName[i],Test1[i],Test2[i],FinalExam[i],TotalAverage (Test1,Test2,FinalExam));
          }
       }
        
    
        public static double TotalAverage(int[] Test1, int[] Test2,int[] FinalExam){
          double TotalAverage = 0;
        // TODO Auto-generated method stub
        int i =0;
    
        for (i=0; i<10;i++){
          if (Test1[i] < Test2[i]){
             TotalAverage = ((0.45*FinalExam[i]) + (0.25*Test1[i]) + (0.3*Test2[i]));
             return TotalAverage;
             
          }else if (Test1[i]>Test2[i]){
             TotalAverage = ((0.45*FinalExam[i]) + (0.3*Test1[i]) + (0.25*Test2[i]));
    
            
    
           }
    
    
    
        }
    
    
         return TotalAverage;
        
        } 
        
    }
    Last edited by BookOfEliX; 11-07-2015 at 10:51 PM.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: How can is solve this?

    First, the program only had one error. But more to the point, why did you fix anything? It's okay to help answer specific questions
    but don't be fixing the code for OPs. Let them fix it themselves. It's part of the learning process.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    Mekulaventure is offline Member
    Join Date
    Nov 2015
    Posts
    3
    Rep Power
    0

    Default Re: How can is solve this?

    i don't understand your response Norm. Please explain better how to do that, thank you.

  6. #6
    Mekulaventure is offline Member
    Join Date
    Nov 2015
    Posts
    3
    Rep Power
    0

    Default Re: How can is solve this?

    Thanks BookofElix but I don't know why the student average column is showing same value. I am thinking the problem is from my looping.

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How can is solve this?

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Can someone solve this ;
    By AccountSaver in forum New To Java
    Replies: 11
    Last Post: 01-26-2014, 03:48 PM
  2. Do not know how to solve this
    By jaylimix in forum New To Java
    Replies: 13
    Last Post: 05-31-2011, 11:42 AM
  3. How to solve this :
    By xp_vista007 in forum New To Java
    Replies: 5
    Last Post: 03-24-2011, 07:19 PM
  4. Please help me solve them
    By quangtrung89 in forum New To Java
    Replies: 2
    Last Post: 11-26-2009, 10:08 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
  •