fork download
  1. import java.util.ArrayList;
  2.  
  3. class Student {
  4. String name;
  5. int[] mark;
  6. double gwa;
  7.  
  8. public Student()
  9. {
  10. name = null;
  11. mark = null;
  12. gwa = 0.0;
  13. }
  14.  
  15. public Student(String[] x) {
  16. name = x[0];
  17. mark = new int[4];
  18. mark[0] = Integer.parseInt(x[1]);
  19. mark[1] = Integer.parseInt(x[2]);
  20. mark[2] = Integer.parseInt(x[3]);
  21. mark[3] = Integer.parseInt(x[4]);
  22. gwa = (mark[0] + mark[1] + mark[2] + mark[3] + mark[3]) / 5.0;
  23. }
  24.  
  25. public String toString() {
  26. return name + "(GWA: " + gwa + ")";
  27. }
  28. }
  29.  
  30. class StudentDetails {
  31. Student[] s;
  32.  
  33. public StudentDetails() {
  34. s = null;
  35. }
  36.  
  37. public void init(String[][] x) {
  38. s = new Student[x.length];
  39. for (int i = 0; i < s.length; ++i)
  40. s[i] = new Student(x[i]);
  41. }
  42.  
  43. public Student getHighestGWA() {
  44. int maxIndex = 0;
  45. for (int i = 1; i < s.length; ++i)
  46. if (s[i].gwa > s[maxIndex].gwa)
  47. maxIndex = i;
  48. return s[maxIndex];
  49. }
  50.  
  51. public Student getLowestGWA() {
  52. int minIndex = 0;
  53. for (int i = 1; i < s.length; ++i)
  54. if (s[i].gwa < s[minIndex].gwa)
  55. minIndex = i;
  56. return s[minIndex];
  57. }
  58.  
  59. public Student getHighestPrelim() {
  60. int maxIndex = 0;
  61. for (int i = 1; i < s.length; ++i)
  62. if (s[i].mark[0] > s[maxIndex].mark[0])
  63. maxIndex = i;
  64. return s[maxIndex];
  65. }
  66.  
  67. public Student getHighestMidterm() {
  68. int maxIndex = 0;
  69. for (int i = 1; i < s.length; ++i)
  70. if (s[i].mark[1] > s[maxIndex].mark[1])
  71. maxIndex = i;
  72. return s[maxIndex];
  73. }
  74.  
  75. public Student getHighestPreFinal() {
  76. int maxIndex = 0;
  77. for (int i = 1; i < s.length; ++i)
  78. if (s[i].mark[2] > s[maxIndex].mark[2])
  79. maxIndex = i;
  80. return s[maxIndex];
  81. }
  82.  
  83. public Student getHighestFinal() {
  84. int maxIndex = 0;
  85. for (int i = 1; i < s.length; ++i)
  86. if (s[i].mark[3] > s[maxIndex].mark[3])
  87. maxIndex = i;
  88. return s[maxIndex];
  89. }
  90.  
  91. public ArrayList<Student> getPassList() {
  92. ArrayList<Student> passList = new ArrayList<Student>();
  93. for (int i = 0; i < s.length; ++i)
  94. if (s[i].gwa >= 75.0)
  95. passList.add(s[i]);
  96. return passList;
  97. }
  98.  
  99. public ArrayList<Student> getFailList() {
  100. ArrayList<Student> passList = new ArrayList<Student>();
  101. for (int i = 0; i < s.length; ++i)
  102. if (s[i].gwa < 75.0)
  103. passList.add(s[i]);
  104. return passList;
  105. }
  106. }
  107.  
  108. public class Main {
  109. public static void main(String[] args) {
  110. String[][] student = {
  111. {"Francis M. Reyes", "92", "89", "93", "94"},
  112. {"Joseph E. Estrada", "80", "70", "81", "78"},
  113. {"Ferdinand E. Marcos", "77", "93", "83", "90"},
  114. {"Cory C. Aquino", "78", "73", "70", "70"},
  115. {"Emilio A. Aguinaldo", "78", "86", "78", "80"},
  116. {"Ramon M. Magsaysay", "91", "81", "78", "80"},
  117. {"Gloria M.Arroyo", "84", "74", "94", "88"}
  118. };
  119.  
  120. StudentDetails stud = new StudentDetails();
  121. stud.init(student);
  122.  
  123. System.out.println("Highest GWA : " + stud.getHighestGWA());
  124. System.out.println(" Lowest GWA : " + stud.getLowestGWA());
  125. System.out.println("Highest Prelim : " + stud.getHighestPrelim());
  126. System.out.println("Highest Midterm : " + stud.getHighestMidterm());
  127. System.out.println("Highest PreFinal: " + stud.getHighestPreFinal());
  128. System.out.println("Highest Final : " + stud.getHighestFinal());
  129.  
  130. ArrayList<Student> temp = null;
  131.  
  132. System.out.println();
  133. temp = stud.getPassList();
  134. System.out.println("Passed Students******");
  135. for (Student tmp : temp)
  136. System.out.println("\t" + tmp);
  137.  
  138. System.out.println();
  139. temp = stud.getFailList();
  140. System.out.println("Failed Students******");
  141. for (Student tmp : temp)
  142. System.out.println("\t" + tmp);
  143. }
  144. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Highest GWA     : Francis M. Reyes(GWA: 92.4)
 Lowest GWA     : Cory C. Aquino(GWA: 72.2)
Highest Prelim  : Francis M. Reyes(GWA: 92.4)
Highest Midterm : Ferdinand E. Marcos(GWA: 86.6)
Highest PreFinal: Gloria M.Arroyo(GWA: 85.6)
Highest Final   : Francis M. Reyes(GWA: 92.4)

Passed Students******
	Francis M. Reyes(GWA: 92.4)
	Joseph E. Estrada(GWA: 77.4)
	Ferdinand E. Marcos(GWA: 86.6)
	Emilio A. Aguinaldo(GWA: 80.4)
	Ramon M. Magsaysay(GWA: 82.0)
	Gloria M.Arroyo(GWA: 85.6)

Failed Students******
	Cory C. Aquino(GWA: 72.2)