CS239 - Advanced Programming | James Madison University |
In-Lab Programming Portion of the Final Examination | Spring 2011 |
This work complies with the JMU Honor Code.
Name: _______________________ Signature: _______________________ Section: _______
Instructions: Answer both of the following questions and submit them using SUBMIT. Be careful to SUBMIT the assignment for your section.
You must work entirely on your own, but you may use the documentation for the Java API and you may compile and execute your solutions. You may receive partial credit and, as always, you may not receive full credit even if your answers pass the SUBMIT tests.
You have been "volunteered" to complete the software for this
sensor. With that in mind, complete the findMax()
method in the following ColorSensor
class.
Your solution should not be recursive.
import java.awt.*; import java.io.*; public class ColorSensor { /** * The entry-point of the application * * @param args The command line arguments (file, position, style) */ public static void main(String[] args) { Color[][] image; int height, left, max, top, value, width; String name; // Process the command line arguments left = Integer.parseInt(args[0]); top = Integer.parseInt(args[1]); width = Integer.parseInt(args[2]); height = Integer.parseInt(args[3]); name = args[4]; // Load the image image = ImageStorage.loadImage(name); // Perform the calculations max = findMax(image, left, top, width, height); // Print the result System.out.println("Maximum: " + max); } /** * Finds the pixel in the given rectangle that * has the maximum sum of the * R and B components and returns that sum. * * @param image The image to use * @param left The coordinate of the left side of the rectangle * @param top The coordinate of the top side of the rectangle * @param width The width of the rectangle * @param height The height of the rectangle * @return The maximum sum in the rectangle */ private static int findMax(Color[][] image, int left, int top, int width, int height) { } }
If the deposit is denoted by d, the interest rate is denoted by r, and the value of the retirement account at the end of year n be denoted by Vn , it follows that:
With that in mind, complete the valueIn()
method in the following RetirementAccount
class.
Your solution must be recursive.
public class RetirementAccount { private double deposit, rate; /** * Explicit Value Constructor * * @param deposit The deposit made (at the beginning of) each year * @param rate The interest rate (which is guaranteed) */ public RetirementAccount(double deposit, double rate) { this.deposit = deposit; this.rate = rate; } /** * Calculates the value of this RetirementAccount in * a given number of years * * @param years The number of years */ public double valueIn(int years) { } }
The Color
class has the following public methods:
Color(int r, int g, int b) // Constructs a Color
int getBlue() // Gets the value of the blue component [0,255]
int getGreen() // Gets the value of the blue component [0,255]
int getRed() // Gets the value of the blue component [0,255]
The following partial implementations of the ColorSensor
and RetirementAccount
classes exist:
Your code will be tested with the following classes and data files: