Minimum value from an array

Hello, in this program I am trying to get the minimum and maximum values of the student marks input with their corresponding ID's. At the moment my logic is wrong as it wil find the highest mark and the highest ID value therfore not doing the required.

Basicly the question is am I using parralel arrays correctly, and how would I get a value from one array with a corresponding (linked) value from another array e.g. I get the mark with the corresponding ID.

import java.util.Scanner;

/**

* Write and test a program that maintains a set of student identity

* numbers (integers in the range 701-799) and the average coursework

* mark for each student (real numbers in the range 0.0 to 100.0).

*

* The program will allow the user to input the identity number and the

* coursework mark for each student. After all the input has been

* entered, the program will display the identity numbers of the students

* with the highest and the lowest marks, then display all the identity

* numbers and corresponding coursework marks in a table, in ascending

* order of coursework mark.

* [Hint: Use parallel arrays.]

*/

publicclass ParallelArrays

{

publicstaticvoid main(String[] args)

{

float maxValue = 0;

int maxValueID = 0;

float minValue = 0;

int minValueID = 0;

System.out.println("Enter number of students");

Scanner scan =new Scanner(System.in);

int numberOfStudents = scan.nextInt();

Scanner scan2 =new Scanner(System.in);

Scanner scan3 =new Scanner(System.in);

int[] IDArray =newint[98];

float[] markArray =newfloat[98];

for(int i = 1; i < (numberOfStudents + 1); i++)

{

System.out.println("Enter student identity number for student: " + i);

IDArray[i] = scan2.nextInt();

if(IDArray[i] > maxValueID)

{

maxValueID = IDArray[i];

}

if(IDArray[i] < minValueID)

{

minValueID = IDArray[i];

}

System.out.println("Enter coursework mark for student: " + i);

markArray[i] = scan3.nextFloat();

if(markArray[i] > maxValue)

{

maxValue = markArray[i];

}

if(markArray[i] < minValue)

{

minValue = markArray[i];

}

}

System.out.println("Student with highest mark: " + maxValueID +" " + maxValue);

System.out.println("Student with lowest mark: " + minValueID +" " + minValue);

System.out.println();

for(int i = 1; i < (numberOfStudents + 1); i++)

{

System.out.println("Student: " + IDArray[i] +" Scores " + markArray[i]);

}

}

}

[4325 byte] By [John4938a] at [2007-10-2 10:56:22]
# 1
You would do better to define a class that holds student information and then build a collection of these objects.
sabre150a at 2007-7-13 3:21:25 > top of Java-index,Java Essentials,Java Programming...
# 2
Double-posted and answered. http://forum.java.sun.com/thread.jspa?threadID=703385
jverda at 2007-7-13 3:21:25 > top of Java-index,Java Essentials,Java Programming...