Question: JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13 Assignment 13 Preparation This assignment will focus on the use of object methods during
| JAVA ASSIGNMENT 13 - Object Methods During Event Handling |
|
|
| Assignment 13 |
| Assignment 13 Preparation |
| This assignment will focus on the use of object methods during event handling. |
| Assignment 13 |
| Assignment 13 Submission |
| Follow the directions below to submit Assignment 13: This assignment will be a modification of the Assignment 12 program (see EncryptionApplication11.java below). Replace the use of String concatenation operations in the methods with StringBuilder or StringBuffer objects and their methods. |
EncryptTextMethods.java ====================== package Utils; import java.util.Scanner; public class EncryptTextMethods { public static String encryptString(String message) { //convert string to character array char stringChars[] = message.toCharArray(); //for each character for(int i=0; i< stringChars.length; i++) { char ch = stringChars[i]; //if character within range of alphabet if(ch <= 'z' && ch >= 'a') { stringChars[i] = (char)('a' + ((int)(ch - 'a') + 1) % 26 ); } } //construct the string message return String.valueOf(stringChars); } public static String decryptString(String message) { //convert string to character array char stringChars[] = message.toCharArray(); //for each character for(int i=0; i< stringChars.length; i++) { char ch = stringChars[i]; //if character within range of alphabet if(ch <= 'z' && ch >= 'a') { stringChars[i] = (char)('a' + ((int)(ch - 'a') - 1) % 26 ); } } //construct the string message return String.valueOf(stringChars); } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Please enter text to encrypt: "); String message = keyboard.nextLine(); message = message.toLowerCase(); String encryptedStr = encryptString(message); System.out.println("Encrypted String: " + encryptedStr); String decryptedStr =decryptString(encryptedStr); System.out.println("Decrypted String : " + decryptedStr); keyboard.close(); } }
EncryptionApplication11.java (this is Assignment 12) ============================
package Utils; import javafx.application.*; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class EncryptionApplication11 extends Application { public void start(Stage primaryStage) { // Create the GridPane pane GridPane pane = new GridPane(); pane.setPadding(new Insets(10, 10, 10, 10)); pane.setVgap(5); // Place nodes in the GridPane pane pane.add(new Label("Input Text:"), 0, 0); TextArea inputTextArea=new TextArea(); inputTextArea.setPromptText("Input text here"); pane.add(inputTextArea, 0, 1); // Create FlowPane pane FlowPane btnPane = new FlowPane(); btnPane.setAlignment(Pos.CENTER); pane.setHgap(5); // Place nodes in the FlowPane pane and place // pane in the GridPane pane btnPane.setPadding(new Insets(10, 10, 10, 10)); btnPane.setHgap(10); Button encryptButton = new Button("Encrypt"); Button clearButton = new Button("Clear"); Button decryptButton = new Button("Decrypt"); btnPane.getChildren().addAll(encryptButton, clearButton, decryptButton); pane.add(btnPane, 0, 2); // Place nodes in the GridPane pane pane.add(new Label("Output Text:"), 0, 3); TextArea outputTextArea=new TextArea(""); outputTextArea.setPromptText("Output text here"); pane.add(outputTextArea, 0, 4); // Create scene and place it on the stage Scene scene = new Scene(pane); primaryStage.setTitle("CPT 236 Encryption Application"); primaryStage.setScene(scene); primaryStage.show(); // Buttons events encryptButton.addEventHandler(ActionEvent.ACTION, new EventHandler
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
