Before continuing on, make sure you’re caught up on the lectures through 5/21.
“Pulling” course materials down from Upstream. As new lesson material or starter code for exercises is added to our central course repository, these are the steps you’ll take to download them into your own workspace repository.
git pull origin main
. We are pulling code from the course source repo into our local repo.You should see in your exercises src
folder an ex03
package with a ComplexNumber
interface and the ComplexNumberImpl
class. This involves completing an implementation for the ComplexNumber
Abstract Data Type. Your work will be going in the ComplexNumberImpl
, where you will complete the implementation, filling in the concrete behavior.
The package ex03 contains a Java interface for the complex number abstract data type. Refer here for a refresher on complex numbers:
https://en.wikipedia.org/wiki/Complex_number
Complete the implementation for the data type started in ComplexNumberImpl
. The ADT is being modeled as an immutable type which means that the multiply and add methods should create new instances to return as their result.
Use the statically defined EQUALS_EPSILON
as the epsilon bound for testing equality of the real and imaginary parts in your implementation of equals. The named constant I is also defined for your convenience if you should need it.
The functional specification of the ADT is as follows (7 methods):
create
: DOUBLE x DOUBLE => COMPLEXThis notation is simply saying that there is a method that takes in two doubles, and returns a complex number.
Canonical operation for creating a new complex number given the magnitudes of its real and imaginary parts.
This corresponds to the Constructor method you will define and implement in your ComplexNumberImpl
class.
real
: COMPLEX => DOUBLEReturns the magnitude of the real part.
This corresponds to the getReal
method you will define and implement in your ComplexNumberImpl
class.
imag
: COMPLEX => DOUBLEReturns the magnitude of the imaginary part.
This corresponds to the getImaginary
method you will define and implement in your ComplexNumberImpl
class.
absolute
: COMPLEX => DOUBLEAbsolute value (see wikipedia page)
This corresponds to the getAbsoluteValue
method you will define and implement in your ComplexNumberImpl
class.
add
: COMPLEX x COMPLEX => COMPLEXAddition (see wikipedia page)
This corresponds to the add
method you will define and implement in your ComplexNumberImpl
class.
multiply
: COMPLEX x COMPLEX => COMPLEXMultiplication (see wikipedia page)
This corresponds to the multiply
method you will define and implement in your ComplexNumberImpl
class.
equals
: COMPLEX x COMPLEX => BOOLEANEquality test. Two complex numbers are equal if both their real and imaginary parts are within EQUALS_EPSILON
of each other.
This corresponds to the equals
method you will define and implement in your ComplexNumberImpl
class.
Your tasks:
ComplexNumberImpl
ComplexNumberImpl
“Push” your work up to GitHub for backup. By creating “commits”, which you can think of as versioned checkpoints in your workspace, you are not at risk of losing your work. It’s easy to revert back to an old version or to restore your entire workspace on a different computer.
main
branch, and needs to be pushed to your remote backup.USERNAME
with your GitHub username:
https://github.com/comp210-ss1-24/summer210-workspace-USERNAME
All that’s left now is to hand-in your work on Gradescope for grading!
Before doing so, you need to know that before an assignment’s deadline you can resubmit work as many times as you need to without penalty. Portions of assignments are autograded and will provide near-immediate feedback. We want you to resubmit as many times as it takes you in order to earn full autograding credit!
Login to Gradescope and select the assignment named “EX03 - ADTs You’ll see an area to upload a zip file. To produce a zip file for autograding, return back to IntelliJ.
Along the bottom of your window, you should see an option to open a terminal integrated into IntelliJ.
Type the following command (all on a single line):
./submit.sh ex03
In the file explorer pane, look to find the zip file named “ex03_submission.zip”. If you right click on this file “Open in -> Finder” on Mac, the zip file’s location on your computer will open. Upload this file to Gradescope to submit your work for this exercise.
We are working on rewriting the script to work for Windows! Until then, please navigate to your course workspace in a File Explorer window. Then right click on the src
folder in your exercises directory and compress the directory into a zip folder. You can name it “ex03_submission.zip”
When you upload it to Gradescope, please delete any files that showed up in the src/
folder that were not actually part of ex03
. You should include both the ComplexNumber
Interface and ComplexNumberImpl
Class in your zip.
Autograding will take a few moments to complete. For this exercise there will be no “human graded” component, but in future exercises and projects there will. Thus, you should expect to score 100 out of 100 possible points on this assignment. If there are issues reported, you are encouraged to try and resolve them and resubmit. If for any reason you aren’t receiving full credit and aren’t sure what to try next, come give us a visit in office hours!