PictureManager Class We have implemented this class for you (CODE BELOW!). This
ID: 3759994 • Letter: P
Question
PictureManager Class
We have implemented this class for you (CODE BELOW!). This class provides several image processing options. You need to use methods of this class during the implementation of the PhotoProcessingSys class. A description of the methods follows.
displayPicture - Displays an image. The image could be in the Eclipse project or it could be a url that corresponds to an image on the web.
clearScreen - Removes any image that have been displayed.
displayLastPicture - Displays the last image that was displayed.
displayPictureBlackWhitePosterize - Takes an image and turns into black and white, posterizes it or both.
displayPictureSelectRedGreenBlue - Takes an image and select the red, green and blue components.
graphicalModeOff/graphicModeOn - In order to run public/secret/release tests we need to disable the image processing (e.g., displaying images). When graphicalModeOff is called only a string will be returned after calling any image processing function.
All the methods described above (except graphicalModeOff/graphicalModeOn) return a string representing the processing that took place.
Address Class
Constructors with four parameters - The parameters are the street, city, state, and zip code. The names of the parameters must be the same names used for the corresponding instance variables. The constructor will throw an IllegalArgumentException exception with the message "Invalid Address Argument" if any parameter is null, or if the zip code has characters others than digits. Notice that any of the parameters can have spaces surrounding them (e.g., " MD "), but you must get rid of them before using the values to initialize the object. The method Character.isDigit can help during the implementation of this method. See the Java API (Character class) for additional information.
Default Constructor - Initializes the object with "8223 Paint Branch Dr.", "College Park", "MD" and "20742" for street, city, state and zip code, respectively. You must implement this constructor using "this".
Copy Constructor
Constructor with one parameter (street) - It will initialize the city, state and zip code with the default values defined above. Notice the street parameter can have spaces surrounding it (e.g. " 4800 Java St. ").
getStreet, getCity, getState, getZipCode - Get methods.
equals - Takes an Address object reference as parameter. You must use "this" in order to compare the current object with the parameter.
toString - Returns a string with the street, city, state and zip code where each field is separated by a space.
You should define default values using static final.
Feel free to add any private methods you understand can help.
This class in an immutable class.
PhotoProcessingSys Class
This class provides access to the image processing facilities the PictureManager class provides. Each PhotoProcessingSys object is associated with a customer and it keeps track of a balance that reflects the cost for any image processing the customer requested. See the PublicTests.java class to have a better understanding of the functionality expected for this class. Remember that some tests have a .txt file associated with them (e.g., pubTest1.txt).
Constructor - Takes as parameters a customer's name (string), and customer's address (four string values representing street, city, state and zip code). An Address object will be created and used to initialize an Address instance variable. To practice exceptions, make sure you catch the IllegalArgumentException while creating the Address object. If an invalid address is provided, just use the default address associated with the Address class. Notice you do not need to generate any error message in this case. There are other tasks associated with the constructor (e.g., initializing balance to 0) that you need to figure out as part of your project.
Default Constructor - Uses "NONAME" for the customer's name and relies on the default address associated with the Address class.
toString - Returns a string with the customer's name, address and balance. Each piece of information is on a line by itself using the messages "Customer Name: ", "Customer Address: ", "Balance: ". See the public tests for format information.
imageTransaction - Takes an image's name (imageName), a task description string (task), a task options string (taskOptions), and a boolean value (graphicalMode). This method is responsible for processing image requests.
The method will first call PictureManager.graphicalModeOn() if graphicalMode is true and PictureManager.graphicalModeOff() otherwise.
Process the specified task. The tasks we can have are:
display - Displays the picture associated with imageName.
clear - Clears the screen of any pictures that have been displayed.
displaylast - Displays the last picture that was displayed.
blackandwhite - Displays a black and white version of imageName.
posterize - Displays a posterized version of imageName.
blackandwhiteposterize - Displays a version of imageName that is in black and white and posterized.
selectcolors - The taskOptions includes the colors that will be selected. We will use r or R to select red, g or G for green and b or B for blue. Notice that many instances can appear in the string and spaces can appear anywhere. Here some examples of strings: "rb", "rBrrrrG",
" r R G ". Once any character appears that color will be selected.
Invalid option - If one of the above options is not provided the method will not do any processing.
showMessageDialog message- After one of the seven image processing has been processed (or an invalid option has been provided) your program must display the message "Continue" using JOptionPage.showMessageDialog. Only call JOptionPane.showMessageDialog if graphicalMode is true.
Return value - The method will return a string that describes the task that took place. For all the seven image processing options the string to return is the string returned by the corresponding PictureManager method. If an invalid image processing option was provided the method will return "Invalid photoProcessing option".
Cost - Each image processing transaction cost $1.00 except selectcolors which is worth $2.00. You must keep track of the balance associated with all the image processing requests. Use a non-static field to keep track of the balance.
Transaction's log - After each image processing transaction you need to store the string (see return value above) in a StringBuffer. This string will be preceded by "Transaction #{NUMBER}" where {NUMBER} represents the transaction's number. Transaction numbers start at 1. Notice that an invalid transaction counts as a transaction.
getTransactions - Returns a String (not StringBuffer) with the transactions.
getBalance - Returns the balance.
package sysutilities;
import javax.swing.*;
import cmsc131PictureLib.*;
public class PictureManager {
private static boolean GRAPHICAL_MODE = true;
public static void graphicalModeOff() {
GRAPHICAL_MODE = false;
}
public static void graphicalModeOn() {
GRAPHICAL_MODE = true;
}
public static void main(String[] args) {
graphicDemo();
nonGraphicDemo();
}
public static void graphicDemo() {
PictureManager.displayPicture("testudo.jpg");
PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png");
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
PictureManager.displayLastPicture();
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true);
PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false);
}
public static void nonGraphicDemo() {
StringBuffer activity = new StringBuffer();
PictureManager.graphicalModeOff();
activity.append(PictureManager.displayPicture("testudo.jpg"));
activity.append(PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png"));
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
activity.append(PictureManager.displayLastPicture());
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true));
activity.append(PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false));
System.out.println(activity);
}
public static String displayPicture(String name) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new Image(name));
}
return "Display " + name + " ";
}
public static String clearScreen() {
if (GRAPHICAL_MODE) {
PictureUtil.clearScreen();
}
return "clearScreen ";
}
public static String displayLastPicture() {
if (GRAPHICAL_MODE) {
PictureUtil.show(PictureUtil.getLastPicDisplayed());
}
return "displayLastPicture ";
}
public static String displayPictureBlackWhitePosterize(String name, boolean blackAndWhite, boolean posterize) {
if (GRAPHICAL_MODE) {
Picture result = new Image(name);
if (blackAndWhite) {
result = new BlackAndWhite(result);
}
if (posterize) {
result = new Posterize(result);
}
PictureUtil.show(result);
}
return "displayPictureBlackWhitePosterize: " + name + ", " + blackAndWhite + posterize + " ";
}
public static String displayPictureSelectRedGreenBlue(String name, boolean red, boolean green, boolean blue) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new SelectComponents(new Image(name), red, green, blue));
}
return "displayPictureSelectRedGreenBlue: " + name + ", " + red + green + blue + " ";
}
Explanation / Answer
package sysutilities;
import javax.swing.*;
import cmsc131PictureLib.*;
public class PictureManager {
private static boolean GRAPHICAL_MODE = true;
public static void graphicalModeOff() {
GRAPHICAL_MODE = false;
}
public static void graphicalModeOn() {
GRAPHICAL_MODE = true;
}
public static void main(String[] args) {
graphicDemo();
nonGraphicDemo();
}
public static void graphicDemo() {
PictureManager.displayPicture("testudo.jpg");
PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png");
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
PictureManager.displayLastPicture();
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false);
PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true);
PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false);
}
public static void nonGraphicDemo() {
StringBuffer activity = new StringBuffer();
PictureManager.graphicalModeOff();
activity.append(PictureManager.displayPicture("testudo.jpg"));
activity.append(PictureManager.displayPicture("http://www.cs.umd.edu/sites/all/themes/cs/logo.png"));
JOptionPane.showMessageDialog(null, "Press OK to clear screen");
PictureManager.clearScreen();
JOptionPane.showMessageDialog(null, "Press OK to display last picture");
activity.append(PictureManager.displayLastPicture());
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", true, true));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, false));
activity.append(PictureManager.displayPictureBlackWhitePosterize("testudo.jpg", false, true));
activity.append(PictureManager.displayPictureSelectRedGreenBlue("testudo.jpg", true, false, false));
System.out.println(activity);
}
public static String displayPicture(String name) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new Image(name));
}
return "Display " + name + " ";
}
public static String clearScreen() {
if (GRAPHICAL_MODE) {
PictureUtil.clearScreen();
}
return "clearScreen ";
}
public static String displayLastPicture() {
if (GRAPHICAL_MODE) {
PictureUtil.show(PictureUtil.getLastPicDisplayed());
}
return "displayLastPicture ";
}
public static String displayPictureBlackWhitePosterize(String name, boolean blackAndWhite, boolean posterize) {
if (GRAPHICAL_MODE) {
Picture result = new Image(name);
if (blackAndWhite) {
result = new BlackAndWhite(result);
}
if (posterize) {
result = new Posterize(result);
}
PictureUtil.show(result);
}
return "displayPictureBlackWhitePosterize: " + name + ", " + blackAndWhite + posterize + " ";
}
public static String displayPictureSelectRedGreenBlue(String name, boolean red, boolean green, boolean blue) {
if (GRAPHICAL_MODE) {
PictureUtil.show(new SelectComponents(new Image(name), red, green, blue));
}
return "displayPictureSelectRedGreenBlue: " + name + ", " + red + green + blue + " ";
}