Help needed on java array
I have an assignment on arrays
On student grades .
The Program should provide the following.
1. Allow a user to enter a number of results (a value between 2 & 25)
2. Process the required number of results by
• Allowing a user to enter a students name
• Allowing a user to enter a students grade (a value between 1 & 100).
3. When data entry is complete, display a menu with the following options
• Display lowest class grade
• Display highest class grade
• Display average class grade
• Sort & Display the grades in ascending order
• Search for an individual student by name
Can someone point me in the right direction with this program .
thanks john
Re: Help needed on java array
Hi John
From what I understand, you just need the following
1. Implement main method
2.Accept the number of results , n.
3.Check whether n is greater than 2 and less than 25
4. Loop the number of results to enter and accept the grades, in an array, for example.
5.Print the following options in the screen.
If you are facing some probs, please put your code forward.
Cheers,
wanderer
(prit4u.wordpress.com)
Re: Help needed on java array
This is what i have done so far but when i enter more that 4 students the programs closes down also where would i enter the sort code ?
Code :
public class program {
public static void main(String[] args) {
// Establishes the rows and columns in the arrays,
// along with the average grades.
int students = 0, tests = 0;
int sum = 0;
// Establishes an array for student names, test grades and averages, and
// the final letter grade.
int grade[][] = new int[25][3];
String student[] = new String[25];
double low=100;
double high=0;
double low1[]={100,100,100} ;
double high1[]={0,0,0} ;
// This allows to set the number of students and test grades that you can enter.
System.out.println("Please enter the number of students you want to enter(1-25): ");
students = EasyIn.getInt();
System.out.println("Please enter the number of test subject grades (1-3): ");
tests = EasyIn.getInt();
System.out.println();
// This allows you to enter the student name, and their test grades.
for( int x = 0; x < students; x++){
System.out.println("Student Name: ");
student[x] = EasyIn.getString();
for(int y = 0; y < tests; y++){
System.out.println("Test Grade " +(y + 1) +": ");
grade[x][y] = EasyIn.getInt();
if (low1[x] > grade[x][y])
{
low1[x] = grade[x][y];
}
if (high1[x] < grade[x][y])
{
high1[x] = grade[x][y];
}
sum += grade[x][y];
if (grade[x][y] < low)
low = grade[x][y];
if (grade[x][y] > high)
high = grade[x][y];
}
// Determines grade letter from the average score of each student.
grade[x][tests] = sum/tests;
sum = 0;
System.out.println();
}
// Out
System.out.printf("%-10s","Student Name" + "\t");
for(int y = 0; y < tests; y++){
System.out.printf("%-10s", "Test " + (y + 1));
}
System.out.println(" Average Grade lowest grade");
for(int q = 0; q < students; q++){
System.out.printf("%-12s", student[q]);
for(int w = 0; w < tests; w++){
System.out.printf("%10.2f", grade[q][w]);
}
System.out.printf("%12.2f", grade[q][tests]);
System.out.printf("%16s", low1[q]);
System.out.printf("%13s", high1[q]);
System.out.println();
}
//
String search_name;
System.out.printf("Please enter student Name to search for: ");
search_name = EasyIn.getString();
for(int q = 0; q < students; q++){
if (student[q].equals(search_name))
{
System.out.printf("Student Name: %s \n", student[q]);
for(int r = 0; r < tests; r++)
{
//System.out.printf("%10.2f", grade[q][r]);
System.out.printf("\n Test %d : Mark : %.2f ",r + 1 , grade[q][r]);
}
System.out.printf("\n\n Lowest mark by %s in all tests : %.2f \n Highest mark by %s in all tests %.2f \n",search_name, low1[q],search_name,high1[q]);
}
//
}
//
System.out.printf("\n\n Lowest overall mark by any student in all tests : %.2f \n Highest overall mark by any student in all tests %.2f \n",low,high);
}
///