Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
How do I identify the fractions if I also have division?
EW says "There are spaces between the values and operations, and fractions won't have the spaces."
3 / 4/5 is "three divided by 4/5"
3/4 / 5 is "3/4 divided by 5"
3/4/5 is EXCEPTIONAL
What do you mean by "swap out" the interface?
You have a UI in the main. It calls sensible helper procedures to do the real work.
How do we use the registers?
I'd do something like the following
Fraction registers[] = new Fraction[8];
...
registers[regnum] = ...;
So, the Calculator class needs methods to store (and maybe get) values from registers?
Yes.
Should the constructor reduce fractions to simplest form an ensure that they have a positive denominator?
Yes.
So someone can write new Fraction(33,-99) and get -1/3?
Yes.
Generally: The idea that you should not have to write nearly-identical code for nearly-identical inputs.
Why not copy-paste-change?
In Scheme
(define square (lambda (x) (* x x)))
We'd like to do something similar in Java, except ...
Dangerous! We don't know until runtime whether or not it's save to use square on a value. Can we square strings? Can we square images?
Ideally, the generalized procedure says "I need this characteristic of the objects", objects say "I have this characteristic", and Java can check both issues.
An interface is a promise to implement procedures.
public Interface Multipliable { public Object multiply(Object other) throws IncompatibleTypeException; }
public Object square(Multipliable m) { return m.multiply(m); }
Promise to meet characteristics with an implemetns clause
public class ComplexNumber implements Multpliable { }
Three methods
Useful for describing interesting textual things
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.