ex15 - public class CumGPA{ private int units; // total...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public class CumGPA{ private int units; // total number of units taken private int points; // total points earned public CumGPA() // constructor { units = 0; points = 0; } public void enterGrade(int u, String grade) // each parameter must have its type { char c = grade.charAt(0); units += u; switch (c) { // poor formatting to save space. Do not use this formatting!! case ('A'): case ('a'): points += (4*u); break; // A and a do the same thing! case ('B'): case ('b'): points += (3*u); break; case ('C'): case ('c'): points += (2*u); break; case ('D'): case ('d'): points += u; break; default: break; } // end of switch (c) } // end of enterGrade public double getGPA() { return ((double) points) / ((double) units); } public double enterGradegetGPA(int u, String grade) { char c = grade.charAt(0); units += u; switch (c) { case ('A'): case ('a'): points += (4*u); break; // A and a do the same thing!...
View Full Document

Page1 / 2

ex15 - public class CumGPA{ private int units; // total...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online