GeoCalc
Overview
For this activity you will complete the implementation of a GEOmetric
CALCulator. The calculator lets you create simple
geometric objects - lines, rectangles, and circles - from points in the
Point class presented in class. Once created, the objects can be queried
for various properties: lines can compute their length; rectangles can
compute their height, width, perimeter, and area; circles can compute
their radius, diameter, circumference and area. A driver program -
geocalc.rb - reads commands from standard input (either the keyboard or a
file using input redirection), creates geometric objects using the command
parameters, and prints out information on the resulting object.
Preparation
- Create a directory GeoCalc at
the top level of your GIT workspace for this course.
- Download the ActivityJournal.txt
- Download the geocalc.zip
archive and extract its contents into the GeoCalc
directory. A directory listing should show the following files:
- circle.rb
- Defines the Circle
class, which depends on (requires) the Point class. The requires
'./point' loads point.rb from the current
directory and makes it available to the body of circle.rb.
You will have to complete code for this class.
- geocalc.rb
- Contains the basic command interpreter - since it uses all the classes
in the system it has a long sequence of requires statements at the head
of the file.
This file is complete - there is nothing you must add or modify within
it. The supported commands are discussed in Activities below.
- line.rb
- Defines the Line
class, which, like Circle,
depends on Point.
You will have to complete code for this class.
- point.rb
- Defines the Point
class. For our purposes the definition is complete; there is
nothing you need add or modify in this file.
- rectangle.rb
- Defines the Rectangle
class, which, like Line
and Circle,
depends on Point.
You will have to complete code for this class.
- Before proceeding to the activities, we strongly suggest you
scan all the Ruby source files to get "a feel" for how all the pieces
fit together. Feel free to ask your instructor or student course
assistant for help.
- Start your Activity Journal.
- To run the program at any time, type the following at the command
prompt:
ruby geocalc.rb
and enter commands via the keyboard. On hamilton, typing CTRL+D
at the start of a line will exit the program. You can also put a
sequence of commands in a file, say commands.txt, and use redirection to
run the tests without typing them again and again:
ruby geocalc.rb <
commands.txt
Activities
- Complete and test (creating a line_test.rb unit test file) the Line
class in line.rb. This is the simplest of the
classes.
- Complete and test (creating a circle_test.rb unit test file) the Circle
class in circle.rb. This is a tad more
challenging that Line.
- Complete and test (creating a rectangle_test.rb unit test file) the Rectangle
class in rectangle.rb. While this may appear
simpler than Circle,
it is set up so you have to do more of the work.
Submission
Submit the Activity Journal with the completed implementation and test files (line, circle, rectangle) to the GeoCalc directory.