Results 1 to 3 of 3
  1. #1
    d24706 is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default Help needed with java arrays code

    Hello,

    I hope someone can help me. I had to do the following assignment( i have most of it done just cant finish it off, question and source code below).

    Question?
    Write a Java program that asks the user to input the scores, as a percentage( e.g 87.4), of 10 students. The scores entered must be stored ina n array.

    The programme must determine:

    The lowest score and its equivalent grade (ie A,B,etc)
    The highest " " " " "
    The average score and its "

    The bit i cant do is tie in the equivalent grade with the lowest highest and average score.

    Code:
    Java Code:
    //Arrayofscores.java
    //This programme asks the user to enter 5 exam scores and store them in an array
    import java.text.*;
    
    public class Arrayofscores
    {
    public static void main(String args[])
    {
    int [] scores = new int[10];
    int smallest, highest,temp,total=0;
    double average =0.0;
    
    //ask the user to enter 10 scores
    for (int i = 0;i<= scores.length-1;i++)
    {
    System.out.print("\n\nEnter Score " + (i+1) + ": ");
    scores[i] = UserInput.getInt();
    }
    
    //find the lowest score
    smallest = scores[0];
    
    for (int i = 1; i <= scores.length-1;i++)
    if (scores[i] < smallest)
    smallest = scores[i];
    
    System.out.println("\nThe lowest score is : " + smallest);
    
    //find the highest score
    highest = scores[0];
    
    for (int i = 1; i <= scores.length-1;i++)
    if (scores[i] > highest)
    highest = scores[i];
    
    System.out.println("\nThe highest score is : " + highest);
    
    //find the average score
    for (int i = 0; i<=scores.length-1;i++)
    total = total + scores[i];
    
    average = total/10.0;
    System.out.println("\nThe average score is : " + average); 
    
    } 
    
    }
    Any suggestions would be greatly appreciated!!

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class ArrayOfScores
    {
        public static void main(String[] args)
        {
            int[] scores = { 3, 7, 2, 5, 4 };
            int smallest, highest, temp, total = 0;
            double average = 0.0;
    
            //find the lowest score
            smallest = Integer.MAX_VALUE;
    
            for (int i = 0; i < scores.length; i++)
                if (scores[i] < smallest)
                    smallest = scores[i];
    
            System.out.println("\nThe lowest score is : " + smallest);
    
            //find the highest score
            highest = -Integer.MAX_VALUE;
    
            for (int i = 0; i < scores.length; i++)
                if (scores[i] > highest)
                    highest = scores[i];
    
            System.out.println("\nThe highest score is : " + highest);
    
            //find the average score
            for (int i = 0; i < scores.length; i++)
                total = total + scores[i];
    
            average = (double)total/scores.length;
            System.out.println("\nThe average score is : " + average); 
        }
    }

  3. #3
    d24706 is offline Member
    Join Date
    Mar 2008
    Posts
    2
    Rep Power
    0

    Default

    ok,i understand that part of the code,what i cant figure out is how the print out say "your highest mark is 94% and thats an a. I probably use an if else statement and call a new method but i cant seem to tie this in with the main method of the code which i already have

Similar Threads

  1. Java Programmers Needed - Indianapolis IN
    By pegitha in forum Jobs Offered
    Replies: 5
    Last Post: 10-20-2008, 07:36 AM
  2. Java experts needed- 30 minute online Java projects
    By michelle in forum Jobs Offered
    Replies: 0
    Last Post: 03-06-2008, 12:47 AM
  3. Java help needed
    By jeneal in forum New To Java
    Replies: 0
    Last Post: 11-21-2007, 04:04 AM
  4. Java developers needed
    By neoris in forum Jobs Offered
    Replies: 0
    Last Post: 11-19-2007, 04:48 PM
  5. Arrays in Java
    By hiranya in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •