PhotoProcessingSys Class This class provides access to the image processing faci
ID: 3758798 • Letter: P
Question
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.
Feel free to add any private methods you understand are needed.
Explanation / Answer
package photo1;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
class PhotoProcessingSys {
static String custname , street , city , state , balance, color;
StringBuffer transLog;
static void funcPhotoProcessingSys(String custname, String street, String city, String state, String zip){
} // end function funcPhProcessSys
static String funcToString(){
String str1;
str1= custname + street + city + state + balance;
return str1;
} // end function toString
static String getBalance(){
return balance;
}
static String getTransactions(){
String trans = " ";
//trans = likst of all transactions;
return trans;
}
static void imageTransaction(String imgNm, String task, String taskOptions, boolean graphicalMode ) {
// this function will process the image requests
// if (graphicalMode) PictureManager.graphicalModeOn();
// else PictureManager.graphicalModeOff();
if ("disp".equals(task)) display();
if ("clear".equals(task)) clear();
if ("dispLast".equals(task)) displayLast();
if ("blkAndWht".equals(task)) blackAndWhite();
if ("selCol".equals(task)) selectColors('r', "rrBgggBBRR");
} // end function image transaction
static void clear() {
custname = street = city = state = balance = " ";
}
static void display() {
System.out.println(" Customer Name: " + custname + " Street: " + street + " City: " + city + " state: " + state + " balance: " + balance) ;
// custname , street , city , state , balance;
}
static void displayLast(){
System.out.println(" Customer Name: " + custname + " Street: " + street + " City: " + city + " state: " + state + " balance: " + balance) ;
}
static void blackAndWhite(){
color = "Black And White";
}
static void blackAndWhitePosterize(){
color = "Black And White Posterize";
}
static void selectColors(char col, String colr){
String color =" ";
if (col == 'r' || col == 'R') color = "Red";
if (col == 'g' || col == 'G') color = "Green";
if (col == 'b' || col == 'B') color = "Blue";
if (colr.equals("rrBgggBBRR")) color = "RedRedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rBgggBBRR")) color = "RedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rrgggBBRR")) color = "RedRedGreenGreenBlueBlueRedRed";
if (colr.equals("rrBgggBBR")) color = "RedRedBlueGreenGreenBlueBlueRed";
if (colr.equals("rrBgggBRR")) color = "RedRedBlueGreenGreenBlueRedRed";
if (colr.equals("rrBgggBBRR")) color = "RedRedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rrBggBBRR")) color = "RedRedBlueGreenBlueBlueRedRed";
if (colr.equals("rrBgggBBRR")) color = "RedRedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rrBgggBRR")) color = "RedRedBlueGreenGreenBlueRedRed";
if (colr.equals("rrBgggBBRR")) color = "RedRedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rrBgggBBRR")) color = "RedRedBlueGreenGreenBlueBlueRedRed";
if (colr.equals("rrBgBBRR")) color = "RedRedBlueBlueBlueRedRed";
if (colr.equals("rrBgggBB")) color = "RedRedBlueGreenGreenBlueBlue";
System.out.println(color);
} // end function selectColors
} // end class PhotoProcessingSys
public class Photo1 extends JApplet {
private static final int JFXPANEL_WIDTH_INT = 300;
private static final int JFXPANEL_HEIGHT_INT = 250;
private static JFXPanel fxContainer;
public static void main(String[] args) {
// create address object
PhotoProcessingSys objAddr = new PhotoProcessingSys();
PhotoProcessingSys.funcPhotoProcessingSys("Jack", "42nd street", "New York", "NY", "1245");
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
} catch (Exception e) {
}
JFrame frame = new JFrame("JavaFX 2 in Swing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JApplet applet = new Photo1();
applet.init();
frame.setContentPane(applet.getContentPane());
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
applet.start();
}
});
}
@Override
public void init() {
fxContainer = new JFXPanel();
fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
add(fxContainer, BorderLayout.CENTER);
// create JavaFX scene
Platform.runLater(new Runnable() {
@Override
public void run() {
createScene();
}
});
}
private void createScene() {
Button btn = new Button();
btn.setText("Process the photos and images");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Photo and image processing in java");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
fxContainer.setScene(new Scene(root));
}
}