We suggest you create a Homework1 Java project in Eclipse and unzip hw1.zip into the src folder. To find the src folder you can right-click on your Homework1 project in the Package Explorer, click on Properties, and then select Resource on the left. The src folder will be under the Location folder given. Then you can right-click on the Homework1 project and refresh it to see all the new files.
Also make sure that you have installed Java 8 and are using a new enough version of Eclipse. To verify this, in Eclipse go to Window, then Preferences, then Java, and then Compiler. Make sure the Compiler compliance level is 1.8. Next right-click on your project (Homework1) in the Package Explorer and click Properties (if you don’t see the Package Explorer, you can view it by going to Window, Show View, Package Explorer). Select Java Build Path and then select the Libraries tab. Make sure the selected JRE System Library is 1.8. If not then click Add Library, then select JRE System Library, select Alternate JRE, and click on Installed JREs. Look for the Java 1.8 installation. If not on the list you can hit search and it will look for it and you can set it to be default. Then you can make sure that the Workspace default JRE on the Add Library window is Java 8.
If either of these didn’t work, first make sure you have the newest Eclipse and Java installed (there is a separate PDF that guides you through this).
In this part you will implement the functions given in Functions.java. For each question, include in the description the (worst-case) runtime and space used by your function (not including the space used by the arguments). You should use Θ-notation. For instance, if your runtime is Θ(n3) you will write Theta(n^3) in the location specified in Functions.java. You may write helper functions if necessary.
We have provided Test classes corresponding to each method you must implement. To run the Test class you must supply the location of the corresponding txt file as the first argument to the program (this will be the src folder where you unzipped homework1.zip to). For example, to test the largestValue function you must run TestLargestValue with argument “/path/to/LargestValue.txt”. To do this either run the program from the terminal with the command line
java TestLargestValue “/path/to/LargestValue.txt”
where you replace /path/to/ with the actual folder that LargestValue.txt is in. Alternatively, you can create a run configuration in Eclipse. To do this select the file in Eclipse (Test- LargestValue.java for example), and select the Run menu, and then Run Configurations. If the Main class listed doesn’t match the class you want to run, you can click the upper left button (has a file with a plus on it) to create a new configuration. Go to the Arguments tab and put (with quotes)
in the Program arguments. You will find 3 test classes for the 3 functions you must imple- ment.
In this part you will write 2 classes that implement the given interface DoubleDoubleFunc- tion. Your two classes must be named AbsoluteValue and Quadratic and should be put in AbsoluteValue.java and Quadratic.java, respectively. AbsoluteValue should have a construc- tor that takes no arguments, and implements the function f (x) = _x _when you call apply. Quadratic should have a constructor that takes 3 doubles, a,b,c, in that order. Quadratic should implement the function q(x) = ax2 + bx + _c _when apply is called. You must also complete the default method apply, and the static method compose in the DoubleDouble- Function interface. You can test your code by running the TestDoubleDoubleFunction class. Note that TestDoubleDoubleFunction.java won’t compile until you create the Quadratic and AbsoluteValue classes correctly. It will throw an exception if you don’t implement the static compose and default apply methods. [Hint: To implement the static compose method you can create another class Composite in Composite.java that implements DoubleDoubleFunc- tion and takes the two DoubleDoubleFunctions f,g in its constructor.]
You should submit the files Functions.java, DoubleDoubleFunction.java, AbsoluteValue.java, Quadratic.java and whatever ever other files you created (like Composite.java) in a single zip file that is uploaded to NYU Classes. Do not include any of the other files (like the testers or the txt files). Make sure not to put any of your files in a named package (i.e., there should be no line starting with the keyword “package” at the top of your java files).
You may ask questions about getting Eclipse working, or getting the testers running in Piazza. You may also ask “one-line questions” where you ask why a single line of code doesn’t compile. Please include the entire compiler error in your post. This etiquette applies to this and all future homeworks.orks perfectly. On windows you would type
FC mydata1.out testdata1.out
For the extra credit, repeat the above process with testdata2.txt, mydata2.out, and test- data2.out.
You should submit the all of your source (.java) files in a single zip file that is uploaded to NYU Classes. For instance, you may have two files called SpreadsheetImpl.java and ColumnComparator.java if you followed the suggestions above. If so, then both of those files should be included in your zip file. Please name your zip file hw2_yourNetID.zip