# Arrays

• December 7th, 2012, 06:59 AM
oonagh
Arrays
Hello can anyone help me write this program using blueJ.

Write a Java program that will:
Firstly prompt the lecturer to enter the number of students in a programming class in
range 1-10.
Secondly, for each student prompt the lecturer to firstly enter their name (string) and
then secondly enter their test score (integer).
Hint – you should use two equal length arrays – one to store the student names and
one to store the student scores. We can then retrieve/update any student name/score
pair by using the same index to access each separate array. You may assume that there
will never be more than 10 students in the class.
Thirdly, calculate and display the following results from the data entered.
1. Average mark
2. Name(s) of student(s) below the average mark
3. Lowest mark
4. Highest mark
5. Name(s) of student(s) achieving highest mark

This is what i have done so far:

import uulib.*;
public class Exam{
public static void main (String [] args)
{
final int SIZE = 10;
int [] mark = new int [SIZE];
String [] name = new String [SIZE];

for (int i = 0; i < mark.length; i=i+1)

{
name [i] = GUI.getString ("Enter name");
mark [i] = GUI.getInt("Enter mark");

}
GUI.show (
"Lowest mark =" + name + lowest (mark) + "\n" +
"Highest mark = " + name + highest ( mark) +
" Average mark = " + name + average (mark));

}

public static int highest (int[] nums)
{
int large = nums [0];

for (int i = 1; 1<nums.length; i=i+1)
{
if (nums [1] > large)
large = nums [i];
}

return large;
}

public static int lowest (int [] nums)
{
int small = nums[0];

for (int i = 1; i<nums.length; i=i+1)
{
if (nums [i] < small)
small = nums [i];
}
return small;
}

public static int average(int[] nums)
{
int total = 0;
for (int i=0; i< nums.length; i++)
{
total = total + nums[i];
}
}

}
• December 7th, 2012, 07:35 AM
Norm
Re: Arrays
[code=java]
[/code]
to get highlighting and preserve formatting.

Can you explain what problems you are having?
• December 7th, 2012, 07:45 AM
oonagh
Re: Arrays
It allows me to input the mark and student name but the program does not show the highest and lowest mark
• December 7th, 2012, 07:53 AM
Norm
Re: Arrays
Quote:

the program does not show the highest and lowest mark
Can you post what the program does show and add some comments about what it should show?