Question

In this homework, create two arrays – studentName and studentScore (String and Int types). Write a...

In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores.

This program should also have the following methods:

    getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.

    getAverage. This method should accept a studentScore array as its argument and return the average of the values in the array. Note: this should use getSum method to get the total.

    printHighest. This method should accept both arrays as its arguments, determine the highest value in the array, and print the highest value along with the student name who earned the highest score.

    printLowest. This method should accept both arrays as its arguments, determine the lowest value in the array, and print the lowest value along with the student name who earned the highest score.

printAboveAvg. This method should accept both arrays as its arguments, determine the average score (using getAverage method), and then list students who earned score above the average.

printBelowAvg. This method should accept both arrays as its arguments, determine the average score (using getAverage method), and then list students who earned score below the average.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

--------------------------------------------------------

Program

import java.util.Scanner;

public class StudentScoreCalculation {
   //Count of students
   public static int count;
   //Scanner object
   public static Scanner sc=new Scanner(System.in);
   public static void main(String[] args) {
       //Prompt for number of students
       System.out.print("Enter number of students going to enter: ");
       count=sc.nextInt();
       sc.nextLine();
       //Create two arrays for student name and score
       String[] studentName=new String[count];
       int[] studentScore=new int[count];
       //Call method to get students information
       getData(studentName,studentScore);
       //call method to print highest scored student details
       printHighest(studentName,studentScore);
       //call method to print lowest scored student details
       printLowest(studentName,studentScore);
       //call method to print above average scored student names
         printAboveAvg(studentName,studentScore);
       //call method to print below average scored student names
         printBelowAvg(studentName,studentScore);

   }
     //Get information about students
   public static void getData(String[] names,int[] scores) {
       for(int i=0;i<count;i++) {
           System.out.print("Enter name of student "+(i+1)+": ");
           names[i]=sc.nextLine();
           while(names[i].equals("")) {
               System.out.print("Enter name of student "+(i+1)+": ");
               names[i]=sc.nextLine();
           }
           System.out.print("Enter score of student "+names[i]+": ");
           scores[i]=sc.nextInt();
           sc.nextLine();
           while(scores[i]<0) {
               System.out.print("Enter score of student "+names[i]+": ");
               scores[i]=sc.nextInt();
               sc.nextLine();
           }
       }
   }
   //Get sum of all scores
   public static int getSum(int[] scores) {
       int sum=0;
       for(int i=0;i<count;i++) {
           sum+=scores[i];
       }
       return sum;
   }
   //Get Average of all scores
       public static double getAverage(int[] scores) {
           int sum=getSum(scores);
           return (double)sum/count;
       }
       //Method to print highest scored student details
       public static void printHighest(String[] names,int[] scores) {
           int highest=0,index=-1;
           for(int i=0;i<count;i++) {
               if(highest<scores[i]) {
                   highest=scores[i];
                   index=i;
               }
           }
           System.out.println("Highest scored student is "+names[index]+ " with score "+highest);
       }
       //Method to print lowest scored student details
               public static void printLowest(String[] names,int[] scores) {
                   int lowest=scores[0],index=0;
                   for(int i=1;i<count;i++) {
                       if(lowest>scores[i]) {
                           lowest=scores[i];
                           index=i;
                       }
                   }
                   System.out.println("Lowest scored student is "+names[index]+ " with score "+lowest);
               }
           //Method to print above average students
           public static void printAboveAvg(String[] names,int[] scores) {
               double avg=getAverage(scores);
               int cnt=0;
               System.out.println("Above average "+avg+" students are: ");
               for(int i=0;i<count;i++) {
                   if(scores[i]>avg) {
                       cnt++;
                       System.out.println(names[i]);
                   }
               }
               if(cnt==0) {
                   System.out.println("No students has above average!!!");
               }
           }
           //Method to print below average students
           public static void printBelowAvg(String[] names,int[] scores) {
               double avg=getAverage(scores);
               int cnt=0;
               System.out.println("Below average "+avg+" students are: ");
               for(int i=0;i<count;i++) {
                   if(scores[i]<avg) {
                       cnt++;
                       System.out.println(names[i]);
                   }
               }
               if(cnt==0) {
                   System.out.println("No students has below average!!!");
               }
           }
}

------------------------------------------------

Output

Enter number of students going to enter: 5
Enter name of student 1: Micheal Jackson
Enter score of student Micheal Jackson: 82
Enter name of student 2: Harry Potter
Enter score of student Harry Potter: 95
Enter name of student 3: Gyan Gill
Enter score of student Gyan Gill: 65
Enter name of student 4: Mariya Tom
Enter score of student Mariya Tom: 48
Enter name of student 5: Millan Mark
Enter score of student Millan Mark: 42
Highest scored student is Harry Potter with score 95
Lowest scored student is Millan Mark with score 42
Above average 66.4 students are:
Micheal Jackson
Harry Potter
Below average 66.4 students are:
Gyan Gill
Mariya Tom
Millan Mark

Add a comment
Know the answer?
Add Answer to:
In this homework, create two arrays – studentName and studentScore (String and Int types). Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write...

    Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write a method (getData) that would ask user to enter a set of data – for example, five student names and corresponding scores. This program should also have the following methods:     getSum. This method should accept a studentScore array as its argument and return the sum of the values in the array.     getAverage. This method should accept a studentScore array as its argument...

  • Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This...

    Java Programming Assignment Write a class named 2DArrayOperations with the following static methods: getTotal . This method should accept a two-dimensional array as its argument and return the total of all the values in the array. Write overloaded versions of this method that work with int , double , and long arrays. (A) getAverage . This method should accept a two-dimensional array as its argument and return the average of all the values in the array. Write overloaded versions of...

  • Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates...

    Java Programming (use jGrasp if not thats fine) Write a Two classes one class that creates a two-dimensional 2 rows by 3 columns double array. This class will have a separate method for the user to populate the array with data values. The other class that has the following methods:   getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array.   getAverage. This method should accept a two-dimensional array...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array...

    This is java, please follow my request and use netbeans. Thank you. A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • please help asap in c++, you dont have to do everything but at least give me...

    please help asap in c++, you dont have to do everything but at least give me a starting idea of how this should look like Write a class Assignment that has private attributes for Name, Possible Points and Earned Points Write a class Student that has private attributes for name and a vector of assignments. The constructor method should require a name. Add a method for get total score that returns the total number of points earned divided by the...

  • in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a...

    in java plz amaining Time: 1 hour, 49 minutes, 15 seconds. Jestion Completion Status: Write a program that asks the user for an input file name, open, read ar number of students is not known. For each student there is a name and and display a letter grade for each student and the average test score fc • openFile: This method open and test the file, if file is not found and exit. Otherwise, return the opened file to the...

  • [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and...

    [JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT