In this extension you complete the functionality of a calculator. You accomplish this using the arithmetic, String, boolean, and casting operations discussed in the book.
To run the unit test, right (control) click on the ComputationsTest file in the package explorer, drag down to Run as and select JUnit Test.The results will be a red or green bar. The red bar means you have errors, and you can see those by clicking on the flagged methods below the red bar. The green bar means your code has passed the test.
Resist the urge to finish coding all of your work! If you are doing something wrong, you will go further down a bad path than you should go. Instead, proceed as follows.
To test the cast operations, use the copy and paste buttons to transfer a value from one type to another.
Some methods in this lab (specifically the casting methods) are not expected to produce any reasonable output. For example, a double cannot be cast to a boolean.Your method must nontheless return some value, so return any value you like, but call the error() method so that the program will report an error in the GUI window.
For example, if a method should return an int but the operation does not make sense, then you would write:
error(); return 0;
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
Credits:
- Dr. Anne Bracy greatly improved the write-up of this exercise.
- Logan Sorrentino implemented the GUI that drives the image processing filters.
The word pixel stands for Picture Element. A pixel is a small part
of a picture. Pixels are the little dots that make up LCD
screens. When you see a low-resolution picture that is grainy, the
grain
you're seeing are the pixels.
Pixels are made up of 3 colors: red, green, and blue (hence the term RGB). The color of a pixel is made up of a combination of the intensities of each of red, green, and blue components. Intensities range from 0 (meaning none of that color is present) to 255 (meaning as much as possible of that color is present). You declare a new pixel by coding
new Color(redValue, greenValue,blueValue)where redValue is the intensity (an integer between 0 and 255) of red, greenValue is the intensity of green, and blueValue is the intensity of blue.
For example, you get the color black with new Color (0,0,0) (0 intensity for all colors). You get red with new Color (255,0,0) (highest intesity for red, 0 intensity for green and blue).
These methods are used by the course software as shown below:
This is the main program you run to see the results of your work.Go ahead and run it as a Java application. You should see a window pop up with some images preloaded.
By the way, you can drag images between the icon panel at the top and the working panels in the middle, or vice versa, so that you can manipulate other images than the ones that are preloaded.You can also load your own images by clicking on the icon that resembles a plus sign.
It is strongly suggested that you test each filter after its completion before you move on to the next filter. This will ensure that you are making progress and not going down a wrong path.Complete the provided stub methods as described below. In the method bodies, use mathematical expressions. Do not use a conditional (if) statement.
Use no conditional execution for this part: only arithmetic expressions as you have learned them in Module 1.
Hint: This is a very simple method.
For example, if the parameter value is 0, you should return 255. If the parameter value is 1, you should return 254, and so on.
Remember that you are not allowed to use conditionals (if) statements for this part of the lab.Hint: : Recall that color components are in the range 0-255. Also, recall that if you divide an int by another int, the result number will be truncated. For example, 130 / 128 = 1, but 125 / 128 = 0.
Note that each pixel of an image is represented as a Color object.
Create and test methods (whose parameters and return values are
- Continue to use no conditional execution for this part: only arithmetic expressions as you have learned them in Module 1.
- To create a new Color, you must specify its red, green, and blue components in that order. For example
Color c = new Color(25,128,0);declares c to be a color with some red (25 out of 255), half of the possible green, and no blue.- If you have a Color c, then you can get its red, green, and blue components as follows:
int red = c.getRed(); int green = c.getGreen(); int blue = c.getBlue();
Colors)
with the following specifications.
The Color class makes this easy because it already provides a brighter() method that returns a brighter color.If c is a color, then c.brighter() is a brighter version of c's color.
Hint: To choose which value, average the three components of the original color.
OK, now you can use if statements!
For your return value, use the constant Color.BLACK or Color.WHITE. It's up to you how to decide when a color's components, taken as a whole, should be considered black or white.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches
This is a continuation of the previous extension. It is therefore suggested that you do the previous extension first.
So run Background as a Java application. You will see two similar images in the source panels, and some other images in the image bar.
Open the Filters class and begin your work as described below.
You can use if statements for this work.
To see this work, perform the following steps:
After dragging these images around the GUI, the results should resemble the following:
Note: No transformation is applied yet. The copy operation appears as the menu choice but the Go button was not pressed.
When you done with this extension, you must be cleared by the TA to receive credit.
- Commit all your work to your repository
- Fill in the form below with the relevant information
- Have a TA check your work
- The TA should check your work and then fill in his or her name
- Click OK while the TA watches