# Help with Arrays assignment

• 11-24-2012, 01:42 AM
frankied22
Help with Arrays assignment
Hey everybody, I am new here. I have a question about a Java assignment I currently have. The assignment is below:

I have to create a program that asks the user to enter how many students there are. Then by use of arrays, I have to have the user enter each students ID, first name, last name, and score. The score must be between 0 and 100. After all that has been entered and stored into arrays, the program has to use a separate method to calculate the average of the scores. After that the program must ask the user to search for a student by entering their ID. If the entered ID is valid, the program will display that students first name, last name, score, and their deviation from the average. If the student pulled up has the highest score, it must display a message saying so. The finding of the deviation from the average must be done with a separate method as well. The program will continue to ask the user to search for a student by ID until the user types "quit".

Basically I am lost right now. So far, I have what I believe to be the correct way to gather the information from the user and store it into four separate arrays. (ID, first name, last name, and score). Right now I am trying to pass the score array to the separate method to calculate the average and return it to the main method to be displayed. Beyond that, I am lost. :( Any help would be greatly appreciated! Thanks!

Here is what I have so far:

import java.util.Scanner;
public class StudentArrays
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("How many students are there? ");
int totalStudents = input.nextInt();

double[] studentID = new double[totalStudents];
String[] firstName = new String[totalStudents];
String[] lastName = new String[totalStudents];
double[] studentScore = new double[totalStudents];

for (int i = 0; i < totalStudents; i++)
{
System.out.printf("Enter the Student ID of Student %d: ", i + 1);
studentID[i] = input.nextDouble();
System.out.printf("Enter the First Name of Student %d: ", i + 1);
firstName[i] = input.next();
System.out.printf("Enter the Last Name of Student %d: ", i + 1);
lastName[i] = input.next();
System.out.printf("Enter the Score of Student %d: ", i + 1);
studentScore[i] = input.nextDouble();
}
}

public static double calculateAverage(double[] studentScore)
{

}
}
• 11-24-2012, 04:51 AM
DarrylBurke
Re: Help with Arrays assignment
• 11-24-2012, 11:27 AM
Darkzombies
Re: Help with Arrays assignment
I would suggest doing the things Darryl linked, also, for
Code:

```Scanner input = new Scanner(System.in); System.out.println("How many students are there? "); int totalStudents = input.nextInt();```
I would try to catch any user-invoked exceptions, such as typing "YOLO" instead of "10".