Question

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 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 a 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 a both arrays as its argument, 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 a both arrays as its argument, determine the average score (using getAverage method), and then list students who earned score above the average.

printBelowAvg. This method should accept a both arrays as its argument, 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

If you have any doubts, please give me comment...

import java.util.*;

public class ArraysExec{

public static void main(String[] args) {

String studentName[] = new String[5];

int studentScore[] = new int[5];

getData(studentName, studentScore);

System.out.println("Average: "+getAverage(studentScore));

printHighest(studentName, studentScore);

printLowest(studentName, studentScore);

printAboveAvg(studentName, studentScore);

printBelowAvg(studentName, studentScore);

}

public static void getData(String studentName[], int studentScore[]){

Scanner keyboard = new Scanner(System.in);

System.out.println("Enter "+studentScore.length+" students Data: ");

for(int i=0; i<studentScore.length; i++){

System.out.print("Enter student name: ");

studentName[i] = keyboard.next();

System.out.print("Enter student score: ");

studentScore[i] = keyboard.nextInt();

}

}

public static int getSum(int studentScore[]){

int sum = 0;

for(int i=0; i<studentScore.length; i++){

sum += studentScore[i];

}

return sum;

}

public static double getAverage(int studentScore[]){

return (double)getSum(studentScore)/studentScore.length;

}

public static void printHighest(String studentName[], int studentScore[]){

int highestScoreInd = 0;

for(int i=1; i<studentName.length; i++){

if(studentScore[i]>studentScore[highestScoreInd]){

highestScoreInd = i;

}

}

System.out.println("Highest score:");

System.out.println("Name: "+studentName[highestScoreInd]);

System.out.println("Score: "+studentScore[highestScoreInd]);

}

public static void printLowest(String studentName[], int studentScore[]){

int lowestScoreInd = 0;

for(int i=1; i<studentName.length; i++){

if(studentScore[i]<studentScore[lowestScoreInd]){

lowestScoreInd = i;

}

}

System.out.println("Lowest score:");

System.out.println("Name: "+studentName[lowestScoreInd]);

System.out.println("Score: "+studentScore[lowestScoreInd]);

}

public static void printAboveAvg(String studentName[], int studentScore[]){

System.out.println("Above average: ");

double avgScore = getAverage(studentScore);

for(int i=0; i<studentScore.length; i++){

if(avgScore<studentScore[i])

System.out.println(studentName[i]+" "+studentScore[i]);

}

}

public static void printBelowAvg(String studentName[], int studentScore[]){

System.out.println("Below average: ");

double avgScore = getAverage(studentScore);

for(int i=0; i<studentScore.length; i++){

if(avgScore>studentScore[i])

System.out.println(studentName[i]+" "+studentScore[i]);

}

}

}

Add a comment
Know the answer?
Add Answer to:
Arrays In this homework, create two arrays – studentName and studentScore (String and Int types). Write...
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
  • 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...

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

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

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

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

  • [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:...

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

  • ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will...

    ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will be responsible for reading in the names and grades for a group of students, then reporting some statistics about those grades. The statistics to be gathered are the number of scores entered, the highest score and the name(s) of the student(s) who earned that score, the lowest score and the name(s) of the student(s) who earned that score, and the average score for 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...

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