Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Collin Emond
- * Date: 9-23-16
- * Course Number: CSC-220
- * Course Name: Intro to Data Structures
- * Problem Number: CSC-220 HW2 One Dimensional Arrays
- * Email: cremond0001@student.stcc.edu
- * Write a method, isEquivalent, that checks whether two int arrays are equivalent.
- * Two arrays are equivalent if they have the same length and contain the same values in any order.
- */
- package Homeworks;
- import java.util.Arrays;
- import javafx.application.Application;
- import javafx.geometry.*;
- import javafx.scene.*;
- import javafx.scene.control.*;
- import javafx.scene.layout.*;
- import javafx.stage.*;
- public class CompareArrays extends Application {
- static TextArea firstArrayTxt;
- static TextField secondArrayTxt;
- static TextField statusTxt;
- Button compareArrayBtn;
- Integer[] intarray;
- Integer[] intarraytwo;
- static String[] elementsinarray;
- static String[] elementsinarray2;
- static String stringone;
- static String stringtwo;
- @Override
- public void start(Stage primaryStage) {
- BorderPane borderPane = new BorderPane();
- borderPane.setTop(getArrayInputBox());
- borderPane.setCenter(getArrayButton());
- borderPane.setBottom(getArrayStatusBox());
- borderPane.setPadding(new Insets(20, 20, 40, 20));
- compareArrayBtn.setOnAction(e -> mainLogic());
- Scene scene = new Scene(borderPane, 400, 500);
- primaryStage.setTitle("Compare Two Arrays");
- primaryStage.setScene(scene);
- primaryStage.show();
- }
- // **********************************************
- private static void mainLogic() {
- stringone = firstArrayTxt.getText().trim();
- stringtwo = secondArrayTxt.getText().trim();
- elementsinarray = stringone.split(" ");
- elementsinarray2 = stringtwo.split(" ");
- int[] intarray1 = new int[elementsinarray.length];
- int[] intarray2 = new int[elementsinarray2.length];
- for (int i = 0; i < elementsinarray.length; i++) {
- intarray1[i] = Integer.parseInt(elementsinarray[i]); //Creates Array of Int w/ same values from the string above
- }
- for (int i = 0; i < elementsinarray2.length; i++) {
- intarray2[i] = Integer.parseInt(elementsinarray2[i]); //Creates Array of Int w/ same values from the string above
- }
- isEqual(intarray1, intarray2);
- }
- // **********************************************
- private static void isEqual(int[] arrayone, int[] arraytwo) {
- Arrays.sort(arrayone);
- Arrays.sort(arraytwo);
- if (arrayone.length == arraytwo.length) {
- statusTxt.appendText("The Arrays are EQUAL");
- } else {
- statusTxt.appendText("The Arrays are NOT EQUAL");
- }
- }
- // **********************************************
- public VBox getArrayInputBox() {
- VBox vBox = new VBox(20);
- firstArrayTxt = new TextArea();
- firstArrayTxt.setPrefHeight(40);
- firstArrayTxt.setPromptText("◎◎◎ Enter number of elements in first array ◎◎◎");
- secondArrayTxt = new TextField();
- secondArrayTxt.setPromptText("◎◎◎ Enter number of elements in second array ◎◎◎");
- vBox.getChildren().addAll(firstArrayTxt, secondArrayTxt);
- vBox.setAlignment(Pos.CENTER);
- return vBox;
- }
- // **********************************************
- public VBox getArrayButton() {
- VBox vBox = new VBox();
- compareArrayBtn = new Button("♛ Determine the equivalence of the two arrays ♛");
- vBox.getChildren().add(compareArrayBtn);
- vBox.setAlignment(Pos.CENTER);
- return vBox;
- }
- // **********************************************
- public VBox getArrayStatusBox() {
- VBox vBox = new VBox();
- statusTxt = new TextField();
- statusTxt.setPromptText("OUTCOME PRINTS HERE");
- statusTxt.setEditable(false);
- statusTxt.setMouseTransparent(true);
- vBox.getChildren().add(statusTxt);
- vBox.setAlignment(Pos.CENTER);
- return vBox;
- }
- // **********************************************
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement