String [ ][ ] student= {{“Francis M. Reyes”,”92”,”89”,”93”,”94”},
{“Joseph E. Estrada”,”80”,”70”,”81”,”78”},
{“Ferdinand E. Marcos”,”77”,”93”,”83”,”90”},
{“Cory C. Aquino”,”78”,”73”,”70”,”70”},
{“Emilio A. Aguinaldo”,”78”,”86”,”78”,”80”},
{“Ramon M. Magsaysay”,”91”,”81”,’’78”,”80”},
{“Gloria M.Arroyo”,”84”,”74”,’’94”,”88”}};
Given the String array student having the initialization shown on the table above get the following:
Name of the student who obtained the highest GWA (10 points)
Name of the student who obtained the lowest GWA (10 points)
GWA=Prelim Grade 20% + Midterm Grade 20 + Pre-final Grade 20 + Final Grade 40%
Name of the student who obtained the highest Prelim Grade (10 points)
Name of the student who obtained the highest Midterm Grade (10 points)
Name of the student who obtained the highest Pre-final Grade (10 points)
Name of the student who obtained the highest Final Grade (10 points)
Names of passing students (GWA>=75) (10 points)
Names of failing students (GWA<75) (10 points)
Are you sure this is to be done in Java? Looks like a database question to me.
thats to be anwered in java
import java.util.ArrayList;
class Student {
String name;
int[] mark;
double gwa;
public Student()
{
name = null;
mark = null;
gwa = 0.0;
}
public Student(String[] x) {
name = x[0];
mark = new int[4];
mark[0] = Integer.parseInt(x[1]);
mark[1] = Integer.parseInt(x[2]);
mark[2] = Integer.parseInt(x[3]);
mark[3] = Integer.parseInt(x[4]);
gwa = (mark[0] + mark[1] + mark[2] + mark[3] + mark[3]) / 5.0;
}
public String toString() {
return name + "(GWA: " + gwa + ")";
}
}
class StudentDetails {
Student[] s;
public StudentDetails() {
s = null;
}
public void init(String[][] x) {
s = new Student[x.length];
for (int i = 0; i < s.length; ++i)
s[i] = new Student(x[i]);
}
public Student getHighestGWA() {
int maxIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].gwa > s[maxIndex].gwa)
maxIndex = i;
return s[maxIndex];
}
public Student getLowestGWA() {
int minIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].gwa < s[minIndex].gwa)
minIndex = i;
return s[minIndex];
}
public Student getHighestPrelim() {
int maxIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].mark[0] > s[maxIndex].mark[0])
maxIndex = i;
return s[maxIndex];
}
public Student getHighestMidterm() {
int maxIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].mark[1] > s[maxIndex].mark[1])
maxIndex = i;
return s[maxIndex];
}
public Student getHighestPreFinal() {
int maxIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].mark[2] > s[maxIndex].mark[2])
maxIndex = i;
return s[maxIndex];
}
public Student getHighestFinal() {
int maxIndex = 0;
for (int i = 1; i < s.length; ++i)
if (s[i].mark[3] > s[maxIndex].mark[3])
maxIndex = i;
return s[maxIndex];
}
public ArrayList<Student> getPassList() {
ArrayList<Student> passList = new ArrayList<Student>();
for (int i = 0; i < s.length; ++i)
if (s[i].gwa >= 75.0)
passList.add(s[i]);
return passList;
}
public ArrayList<Student> getFailList() {
ArrayList<Student> passList = new ArrayList<Student>();
for (int i = 0; i < s.length; ++i)
if (s[i].gwa < 75.0)
passList.add(s[i]);
return passList;
}
}
public class Main {
public static void main(String[] args) {
String[][] student = {
{"Francis M. Reyes", "92", "89", "93", "94"},
{"Joseph E. Estrada", "80", "70", "81", "78"},
{"Ferdinand E. Marcos", "77", "93", "83", "90"},
{"Cory C. Aquino", "78", "73", "70", "70"},
{"Emilio A. Aguinaldo", "78", "86", "78", "80"},
{"Ramon M. Magsaysay", "91", "81", "78", "80"},
{"Gloria M.Arroyo", "84", "74", "94", "88"}
};
StudentDetails stud = new StudentDetails();
stud.init(student);
System.out.println("Highest GWA : " + stud.getHighestGWA());
System.out.println(" Lowest GWA : " + stud.getLowestGWA());
System.out.println("Highest Prelim : " + stud.getHighestPrelim());
System.out.println("Highest Midterm : " + stud.getHighestMidterm());
System.out.println("Highest PreFinal: " + stud.getHighestPreFinal());
System.out.println("Highest Final : " + stud.getHighestFinal());
ArrayList<Student> temp = null;
System.out.println();
temp = stud.getPassList();
System.out.println("Passed Students******");
for (Student tmp : temp)
System.out.println("\t" + tmp);
System.out.println();
temp = stud.getFailList();
System.out.println("Failed Students******");
for (Student tmp : temp)
System.out.println("\t" + tmp);
}
}
This one is a naive implementation. No sorts of optimizations are done in here. I hope this is what you wanted.
well, thanks dude…
code is not working.
check the online link i gave. it shows the working code with output
i already check it. but when i run it, its not working. what should i do with this? thanks
Which part of this is not working for you? Is it that the output format is not the way, as originally intended? Can you give more details?