Algorithms and OOD (CSC 207 2014S) : EBoards

CSC207.01 2014S, Class 14: Interfaces and Polymorphism


Overview

Preliminaries

Admin

Upcoming Work

Questions on the Homework

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.

Polymorphism

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 ...

Interfaces

Polymorphism in Java

Text Boxes

Three methods

Useful for describing interesting textual things

Lab

Copyright (c) 2013-14 Samuel A. Rebelsky.

Creative Commons License

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.