3.3. Exercises

  1. Write an equals method for the fraction class that returns true is two fractions are equal and false otherwise.

  1. Write sub, mul, and div for the Fraction class.

  1. Write a class that represents a Rectangle. Your constructor should take a length and a width. Write an area method that returns the area of the rectangle.

    Before you keep reading...

    Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.

  1. Write a class the old way that represents a Rectangle. Your constructor should take a length and a width. Write an area method that returns the area of the rectangle.

  1. Write a class Stack that implements the stack data type, with a push, pop, peek, size, and isEmpty as the methods.

  1. Write a class Queue that implements the queue data type, with enqueue, dequeue, peek, size, and isEmpty as the methods.

  1. Write a class Cat that inherits from Animal.