package pr02; import java.text.DecimalFormat; public class GradeList { private int[] grades; private double[] weights; private DecimalFormat twoPlaces; public GradeList(int size) { grades = new int[size]; weights = new double[size]; for (int i=0;i grades.length)) return false; grades[index-1] = grade; return true; } public int getGrade(int index) { if ((index < 1) || (index > grades.length)) return -1; return grades[index-1]; } public boolean setWeight(double weight, int index) { if ((index < 1) || (index > grades.length)) return false; if (weight < 0) return false; weights[index-1] = weight; return true; } public double getWeight(int index) { if ((index < 1) || (index > grades.length)) return -1; return weights[index-1]; } public double getAverage() { if (grades.length == 0) return 0.0; double sum = 0; for (int i=0;i grades[i])) min = grades[i]; return min; } private String fourPlaces(int n) { String s = "" + n; while (s.length() < 4) s = " " + s; return s; } private String weightString(double weight) { return twoPlaces.format(weight); } }