ComplexNumber class, which will be capable of graphically plotting each number on a coordinate plane.
Create your project in Eclipse, and then import the new version of
wheels: coordwheels.jar. (This version also includes the source code.)
The only difference in the new
wheels is that I have extended the
Frame class so that it displays an x and y-axis and plots shapes relative to the center of the screen. So, you will be able to draw lines as you did in Assignment 2; however, you must create a
CoordinateFrame object rather than a
Frame object before you start drawing. (This will be done as a static member of
(There is also slight hiccup in that you may need to call
CoordinateFrame after you finish drawing to get the shapes to render properly without having to minimize the window first.)
ComplexNumber class that includes the following details:
Static variables (protected):
CoordinateFrame display = new CoordinateFrame(); -- from wheels.users
Instance variables (private):
Color color -- this a java.awt.Color
ComplexNumber(double real, double imaginary) -- Should construct the given
ComplexNumber, setting its color to
String toString() -- Returns a string of the form
"real + imaginaryi".
void setColor(Color c)
void draw() -- Will draw a line from the origin (0,0) to this ComplexNumber (real, imaginary) in this number's current color.
void drawFrom(ComplexNumber source) -- Will draw a line from the given source point to this number, using this number's color.
Remember, you may have to call
display.repaint() at the end of your draw methods.
Now, to test the new
ComplexNumber class, write a
main method in the
ComplexNumber class. In this method, you should:
- Create a couple complex numbers. This should produce a CoordinateFrame on the screen with gray coordinates already drawn on it.
- Call the draw methods of the numbers you created, and they should show up on the frame.
- Test your other methods.
For the first time, I will be enforcing coding standards, so be sure to format and document your code properly.
If written correctly, your
ComplexNumber class will work with my Plotter.java. If you get any compile errors, fix your
ComplexNumber class to match the specifications above.
Plotter is a short little program that prompts for a series of ComplexNumber coordinates and draws them.
What to Submit
Attach your ComplexNumber.java file to an email.
- Example code from lab?
- Right here: Circle.java
Out of 10 points:
- 1 - Submission
- Follows required submission policies.
- 2 - Coding Standards
- 1 - Correct constructor
- 3 - Correct methods
toString and color methods each worth 0.5 points.
- 1 - Main method as described
- Draws at least a couple complex numbers on the frame.
- 2 -
Plotter compiles and runs correctly using your