Algorithms and OOD (CSC 207 2013F) : Assignments

Assignment 4: More Fun with Fractions


This assignment is currently in draft form.

Due: 10:30 p.m., Tuesday, 24 September 2013

Summary: In this assignment, you will continue your exploration of a simple Fraction class, extending the class to provide a more maximalist interface. You will also use that class to build an interactive calculator.

Purposes: To give you experience designing and implementing classes. To give you some opportunity to build interactive applications.

Collaboration: You must work in a group. Your group can be of size two, three, or four. Your group must include at least one person you did not work with on a prior assignment.

Wrapper (Prologue): Individually read through this assignment and make sure that you understand what is required. Then use the form available at http://bit.ly/207hw4pro to indicate (a) how long you think this assignment will take and (b) what you think will be the most challenging aspect of this assignment.

Wrapper (Epilogue): When you are done with the assignment, fill out the form available at http://bit.ly/207hw4epi to indicate (a) how long the assignment took, (b) what the most challenging part of the assignment was, and (c) something important you learned from doing the assignment. If you find that the assignment took much less or much more time than you expected, also include (d) a note as to what might have led to that difference.

Submitting: Please put all of your work in a GitHub repository named csc207-hw4. Email me the address of that repository. Please title your email “CSC207 2013F Assignment 4 (Your Names)”.

Warning: So that this assignment is a learning experience for everyone, we may spend class time publicly critiquing your work.

Preparation

a. Create a new Eclipse project for this assignment. You can name the project whatever you like, provided it's not in bad taste.

b. If you'd like, you may copy the Fraction class that we wrote in class. If you do so, make sure to include an "@author CSC 207 2013F" at the top.

Assignment

Part A: A Fraction Class

Finish implementing the Fraction class that you started to design in assignment 2 and that we worked on in class. Make sure to write a few tests for each method you implement.

Part B: A Calculator Class

Implement a class, Calculator, that supports simple calculations using fractions and integers. Your calculator should support at least eight storage elements, labeled r0 ... r8.

Your calculator class should support evaluate(String expression), where experession is either an expression over fractions and storage elements or an “assignment” of the form ri = expression.

Note that evaluate should throw an appropriate exception if the expression is malformed. (Ideally, you should find a way to indicate the location of the error in the expression.)

Your calculator class should also support evaluate(String[] expressions), the evaluation of a sequence of expressions. For this, you should return an array of the values created for each expression.

Part C: A User Interface

Create a user interface for the calculator. Your interface will primarily use the read-eval-print loop (aka REPL): read an expression, evaluate that expression, print the result, and do it all over again. You should find a nice way to report the errors.

Citations

This assignment grew from exercises in class and some discussions with students.

Copyright (c) 2013 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.