50 likes | 129 Views
Lecture 14: Review of Term (So FAR). Methods.
E N D
Methods public classSum {private intval;Sum(intv) { val = v; }Sum() {this(0); }void inc(inti) {val += i; }void inc(Sum s) {val += s.val; }public static void main(String[] args) {Sumsq = new Sum();SumsumSq = new Sum(); for (inti = 0; i < 4; i++) {sq.inc((2 * i) + 1);sumSq.inc(sq);System.out.println(sq.val); }System.out.println(sumSq.val);} }
Methods public classSumTwoextends Sum {SumTwo(intv) { super(v); }void inc(inti, intj) {inc(i+ j); }public static void main(String[] args) {SumnotFib = new SumTwo(0);intfst = 0;intsnd = 1; for (inti = 0; i < 4; i++) {notFib.inc(fst, snd);inttmp = fst + snd;fst = snd;snd = tmp; }System.out.println(notFib.val);} }
For Midterm • You can use on this midterm: • You can always use yourtextbook & notes • Printout of slides IF has notes on that day's slides • At the same time, you may NOT use: • Computer, calculator, cell phone, or similar • Copies of daily activities and/or solutions • Friends, Romans, countrymen or their ears
How to Prepare for Midterm DO DON'T • Make cheat sheets for the test • Review how parts of Java work • Add post-its to important pages • Memorize • Drink case of 40s before test • Use post-its as clothing