Results 1 to 3 of 3
  1. #1
    frankied22 is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default 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)
    {



    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default Re: Help with Arrays assignment

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Help with Arrays assignment

    I would suggest doing the things Darryl linked, also, for
    Java 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".

Similar Threads

  1. Copying Single Arrays to 2-D Arrays
    By jmscarlet9 in forum New To Java
    Replies: 7
    Last Post: 04-03-2012, 12:17 AM
  2. need help with basic programming assignment (with arrays)
    By magictricks1020 in forum New To Java
    Replies: 11
    Last Post: 05-03-2011, 03:19 AM
  3. Urgent! Java Assignment with loops in Arrays
    By Xeher in forum New To Java
    Replies: 4
    Last Post: 11-28-2010, 01:49 AM
  4. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 02:40 AM
  5. Initialization and re-assignment of arrays
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 09:38 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
  •