Statistics:
(including three-point curve) mean 22.250 (979.000/44) stddev 6.906 median 23.000 midrange 18.000-28.000 # avg 1 6.57 / 10 2 6.52 / 10 3 6.16 / 10 + 3-point curve
Suppose we add the following method definition to our Bank class.
public class Bank { // : (definitions of other methods and variables) public void remove(int i) throws NoSuchElementException { if(i < 0) { throw new NoSuchElementException("negative index"); } else if(i >= num_accts) { throw new NoSuchElementException("index too large"); } else { num_accts--; accts[i] = num_accts; } } }
public static void run() { Bank first = new Bank(); // : (code that inserts accounts into the bank) }
Suppose we have the following two class definitions.
class A { public int f(int x) { return 2 * x; } public int g(int x) { return f(x * 3); } } | class B extends A { public int f(int x) { return 5 * x; } public int h(int x) { return f(7 * x); } } |
public static void run() { B b = new B(); IO.println(b.f(1) + " " + b.g(1) + " " + b.h(1)); A a = b; IO.println(a.f(1) + " " + a.g(1)); }
Define a class PassCount to track whether all the students of a class have passed a test. It should support the following methods.
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 static void run() { Bank first = new Bank(); // : (code that inserts accounts into the bank) try { first.remove(2); } catch(NoSuchElementException e) { IO.println(e.getMessage()); } }
5 15 35 5 15
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; } }