Algorithms and OOD (CSC 207 2014F) : EBoards

# CSC207.01 2014F, Class 10: Pause for Breath

Overview

• Preliminaries.
• Upcoming Work.
• Extra Credit.
• Questions.
• Labs.

## Preliminaries

• Continue partners.
• Two labs, but both short.
• I'll try not to talk much today (after the preliminaries).
• I sent out notes on HW 3 yesterday. Please do take the time to read them, as they apply to many of your assignments.
• I sent out some comments on HW 4 yesterday. I'll take additional questions at the end of the preliminaries.
• I sent out peer review links yesterday. It sounds like some of you didn't get them. I'll resend if you email me.
• I brought a few more copies of the HFOSS survey. I would like you to fill it out if you are willing. (No bribes for doing so, other than an expectation of cookies in a future class.)

### Campus Events of Interest

• Become a Peer Advisor in CS (PACS?)
• Rosenfield seminar on Scotland, Tuesday noon and Thursday afternoon.
• Rosenfield internship talks, Wednesday and Thursday.
• Rebecca Hamlin book talk Wednesday at 4:15 pm.

### Extra Credit Opportunities

• Convo Wednesday: President Kington
• CS resume review session, Thursday, 4:30 pm.
• CS Table, Friday: User Tracking

#### Peer Support

• CS Extras Thursday the 25: ZW and EF, and AHD, and others on MIST.

#### Miscellaneous

• Project IGNITE!

### Questions

• Can we use vectors in the segmenting strings problem?
• Sure. As long as your return an array.
• Can you go through the long string example?
• Yes. See whiteboard.
• Do we have to support negative numbers in our calculator?
• Yes, except for exponents. It can crash for negative exponents.
• Do we have to support fractional exponents?
• No. (Hmmm ... okay, you don'thave to support exponentiation in your fractional calculator.)
• How does the weirdo `equals` method work.

``````class Fraction
{
BigInteger num;
BigInteger denom;

...
public boolean equals(Object other)
{
// If the objects occupy the same area of memeory, they are
// the same
if (this == other)
{
return true;
} // this == other
// If the other object is a Fraction
else if (other instanceof Fraction)
{
return this.equals((Fraction) other);
// Fraction frac = (Fraction) other;
// return this.num.equals(frac.num) &&
//    this.denom.equals(frac.denom);
} // other is a Fraction
// If the other object is a BigInteger
else if (other instanceof BigInteger)
{
return this.equals((BigInteger) other);
} // other is BigInteger
// Everything else is different.
else
return false;
} // equals(Object)

/**
* Determine if this fraction is the same as a BigInteger.
* A fraction is the same as a BigInteger when the denominator
* of the fraction is 1 and the numerator is the same as the
* BigInteger.
*/
public boolean equals(BigInteger other)
{
return this.denom.equals(BigInteger.ONE) &&
this.num.equals(other);
} // equals(BigInteger)

/**
* Determine if this fraction is the same as another fraction.
* Two fractions are the same if they have the same numerator
* and denominator.
*/
public boolean equals(Fraction other)
{
return this.num.equals(other.num) &&
this.denom.equals(other.denom);
} // equals(Fraction)

} // class Fraction

checkEquals(new Fraction(1,2), Calculator.eval1("1/2"));

// How JUnit deals with this.
//   Evaluate the first value, call it v1
//   Evaluate the second value, call it v2
//   Call v1.equals(v2)
//     If true, does nothing
//     If false, reports an error
//   JUnit assumes v1 and v2 are objects
//   So Java looks for a method with signature equals(Object)
//     to do the comparison.

checkEquals(new Fraction(1,2).toString(), Calculator.eval1("1/2").toString());
``````
• When we put the `simplify` method (using `gcd`) in the constructor, does it need to be anywhere else?

• If you only have one constructor, no.
• If you have multiple constructors, it probably needs to happen in all of them (or all appropriate ones).
• Can we call constructors from other constructors?

• Yes

public Fraction(BigInteger num, BigInteger denom) { this.num = num; this.denom = denom; } // Fraction(BigInteger, BigInteger)

public Fraction(int num, int denom) { this(new BigInteger(num), new BigInteger(denom)); } // Fraction(int, int)