Algorithms and OOD (CSC 207 2013F) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Admin
Can I store the numerator and denominator as BigInteger values?
Certainly.
Why doesn't my equals
method work?
public boolean equals(Fraction other) {
return this.numerator.equals(other.numerator) &&
this.denominator.equals(other.denominator);
} // equals(Fraction)
If you write an
equals
method with a signature ofequals(Fraction other)
, the Java often doesen't know to call it. In general, it thinks it should callequals(Object other)
. So, you have to cast.
public boolean equals(Object other) {
return this.equals((Fraction) other);
} // equals(Object)
or
public boolean equals(Object other) {
return (other instanceof Fraction) &&
(this.equals((Fraction) other));
} // equals(Object)
Why does the constructor for fractions fail?
I think I wrote something like
if (this.denominator.equals(...))
without first asssigning tothis.denominator
. (Only some of you seem to have had this problem.)
We compare two fractions by subtracting one from the other and then return the numerator as converted to an integer. What do you think about this awesome approach?
Okay in theory, but ... overflow issues. Try using .signum() or use BigInteger.compareTo.
Can we assume that our procedures work?
No. But simple tests can test multiple procedures (e.g., constructor and toString().
What should evaluate
return when given an assignment?
The value assigned.
Is this like C in which you can have beautiful stuff like r0 = r2 = r0 + 1
?
No, you do not have to support that.
How would you have solved the "separate strings" problem from HW3?
// Count how many times the separator appears
// Repeatedly use indexOf
// Build the array of the correct size
// Step through the string (using indexOf), with substring
Continue Friday's lab.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] [FAQ] [IRC] [Teaching & Learning]
Current: [Assignment] [EBoard] [Lab] [Outline] [Partners] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions]
Related Courses: [CSC 152 2006S (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 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.