Define a class PassCount to track whether all the
students of a class have passed
a test. It should support the following methods.
Note that, to accomplish this, a PassCount object need not remember every single grade --- that is, you do not need to use arrays: It just needs to remember whether any of the ones it has seen were below 60.public class PassCountTest { public static void run() { PassCount a = new PassCount(); a.addGrade(45.0); a.addGrade(76.0); IO.println(a.isAnyFailing()); // should print ``true'' PassCount b = new PassCount(); b.addGrade(60.0); IO.println(b.isAnyFailing()); // should print ``false'' } }
public class PassCount { private boolean found_fail; public PassCount() { found_fail = false; } public void addGrade(double grade) { if(grade < 60.0) { found_fail = true; } } public boolean isAnyFailing() { return found_fail; } }