Java Actual Relative Calculator (JavaFX Version) - Implementing Computing Functions

Summary of this section: Implementing kinship calculations

Function 1: Implement computing

Create a RelationShipData.java file under the data folder, which is mainly a two-dimensional array, relational chain data.

The contents are as follows:

package kindredCalculator.data;
​
public class RelationShipData {
    public String[][] getRelationShipData() {
        String[][] relationshipData = {
                {"I", "Dad", "Mom", "brother", "Younger brother", "sister", "Younger sister", "Son", "daughter", "Wife", "husband", "Unknown Relatives"},
                {"Dad", "grandpa", "grandma", "uncle", "uncle", "aunt", "aunt", "I", "Younger sister", "Mom", "No such relationship exists", "Unknown Relatives"},
                {"Mom", "Grandpa", "grandmother", "oldest maternal uncle", "Uncle", "Aunt", "Aunt", "I", "Younger sister", "No such relationship exists", "Dad", "Unknown Relatives"},
                {"brother", "Dad", "Mom", "brother", "I", "sister", "Younger sister", "Nephew", "niece", "Sister-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Younger brother", "Dad", "Mom", "I", "Younger brother", "sister", "Younger sister", "Nephew", "niece", "Sister-in-law", "No such relationship exists", "Unknown Relatives"},
                {"sister", "Dad", "Mom", "brother", "I", "sister", "Younger sister", "nephew", "Sister's daughter", "No such relationship exists", "Sister-in-law", "Unknown Relatives"},
                {"Younger sister", "Dad", "Mom", "I", "Younger brother", "sister", "Younger sister", "nephew", "Sister's daughter", "No such relationship exists", "Sister-in-law", "Unknown Relatives"},
                {"Son", "I", "Wife", "brother", "Younger brother", "sister", "Younger sister", "Grandson", "granddaughter", "Daughter-in-law", "No such relationship exists", "Unknown Relatives"},
                {"daughter", "I", "Wife", "brother", "Younger brother", "sister", "Younger sister", "Grandson", "Daughter's daughter", "No such relationship exists", "son-in-law", "Unknown Relatives"},
                {"Wife", "father-in-law", "mother-in-law", "Uncle", "Uncle", "Sister-in-law", "Sister-in-law", "Son", "daughter", "No such relationship exists", "I", "Unknown Relatives"},
                {"husband", "No such relationship exists", "No such relationship exists", "No such relationship exists", "No such relationship exists", "No such relationship exists", "No such relationship exists", "No such relationship exists", "No such relationship exists",
                        "No such relationship exists", "No such relationship exists", "Unknown Relatives"},
                {"grandpa", "Great-grandfather", "Great grandmother", "Grandfather", "Grandfather", "Grandma and aunt", "Grandma and aunt", "Dad", "aunt", "grandma", "No such relationship exists", "Unknown Relatives"},
                {"grandma", "Great Grandfather", "Great Grandmother", "mother's brother", "mother's brother", "Grandma and aunt", "Grandma and aunt", "Dad", "aunt", "No such relationship exists", "grandpa", "Unknown Relatives"},
                {"uncle", "grandpa", "grandma", "uncle", "uncle", "aunt", "aunt", "Elder male cousin", "Elder female cousin", "Aunt", "No such relationship exists", "Unknown Relatives"},
                {"uncle", "grandpa", "grandma", "uncle", "uncle", "aunt", "aunt", "Younger male cousin", "Younger female cousin", "aunt", "No such relationship exists", "Unknown Relatives"},
                {"aunt", "grandpa", "grandma", "uncle", "uncle", "aunt", "aunt", "Cousin", "Aunt and Sister", "No such relationship exists", "uncle", "Unknown Relatives"},
                {"Grandpa", "Grandfather", "Grandmother", "Grandfather", "Uncle Grandfather", "Grandmother", "Grandmother", "uncle", "Mom", "grandmother", "No such relationship exists", "Unknown Relatives"},
                {"grandmother", "Grandfather", "Grandmother Grandmother", "Uncle", "Uncle", "sister of one's maternal grandmother", "sister of one's maternal grandmother", "uncle", "Mom", "No such relationship exists", "Grandpa", "Unknown Relatives"},
                {"oldest maternal uncle", "Grandpa", "grandmother", "oldest maternal uncle", "uncle", "Aunt", "Mom", "Uncle and Cousin", "Uncle, Cousin", "Uncle and aunt", "No such relationship exists", "Unknown Relatives"},
                {"Uncle", "Grandpa", "grandmother", "uncle", "Uncle", "Mom", "mother's youngest sister-aunt", "Uncle and Cousin", "Uncle, Cousin", "Little Aunt", "No such relationship exists", "Unknown Relatives"},
                {"Aunt", "Grandpa", "grandmother", "oldest maternal uncle", "uncle", "Aunt", "Mom", "Aunts and cousins", "Aunts and cousins", "No such relationship exists", "Aunt and Aunt", "Unknown Relatives"},
                {"Aunt", "Grandpa", "grandmother", "uncle", "Uncle", "Mom", "mother's youngest sister-aunt", "Aunts and cousins", "Aunts and cousins", "No such relationship exists", "Little Aunt", "Unknown Relatives"},
                {"Nephew", "brother", "Sister-in-law", "Nephew", "Nephew", "niece", "niece", "nephews", "Nephews and granddaughters", "Nephew-in-law", "No such relationship exists", "Unknown Relatives"},
                {"niece", "brother", "Sister-in-law", "Nephew", "Nephew", "niece", "niece", "External Nephew", "Grandniece", "No such relationship exists", "Nephew-in-law", "Unknown Relatives"},
                {"Sister-in-law", "In-laws", "In-laws", "older brother-in-law", "In-laws", "Sister in Marriage", "Sister in Marriage", "Nephew", "niece", "No such relationship exists", "brother", "Unknown Relatives"},
                {"Sister-in-law", "In-laws", "In-laws", "older brother-in-law", "In-laws", "Sister in Marriage", "Sister in Marriage", "Nephew", "niece", "No such relationship exists", "Younger brother", "Unknown Relatives"},
                {"nephew", "Sister-in-law", "sister", "nephew", "nephew", "Sister's daughter", "Sister's daughter", "Nephews and grandchildren", "Nephew's granddaughter", "Nephew's daughter-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Sister's daughter", "Sister-in-law", "sister", "nephew", "nephew", "Sister's daughter", "Sister's daughter", "Nephews and grandchildren", "Nephew's granddaughter", "No such relationship exists", "Nephew's son-in-law", "Unknown Relatives"},
                {"Sister-in-law", "Married Abbot", "In-laws", "older brother-in-law", "In-laws", "Sister in Marriage", "Sister in Marriage", "nephew", "Sister's daughter", "sister", "No such relationship exists", "Unknown Relatives"},
                {"Sister-in-law", "Married Abbot", "In-laws", "older brother-in-law", "In-laws", "Sister in Marriage", "Sister in Marriage", "nephew", "Sister's daughter", "Younger sister", "No such relationship exists", "Unknown Relatives"},
                {"Grandson", "Son", "Daughter-in-law", "Grandson", "Grandson", "granddaughter", "granddaughter", "Great-grandson", "Great-granddaughter", "grandson's wife", "No such relationship exists", "Unknown Relatives"},
                {"granddaughter", "Son", "Daughter-in-law", "Grandson", "Grandson", "granddaughter", "granddaughter", "Great grandchildren", "Great-granddaughter", "No such relationship exists", "Son-in-law", "Unknown Relatives"},
                {"Daughter-in-law", "Family and Family", "son's or daughter's mother-in-law", "Married Nephew", "Married Nephew", "Married Nephew", "Married Nephew", "Grandson", "granddaughter", "No such relationship exists", "Son", "Unknown Relatives"},
                {"Daughter's daughter", "son-in-law", "daughter", "Grandson", "Grandson", "Daughter's daughter", "Daughter's daughter", "Grandparents", "Granddaughter", "No such relationship exists", "daughter's son-in-law", "Unknown Relatives"},
                {"Grandson", "son-in-law", "daughter", "Grandson", "Grandson", "Daughter's daughter", "Daughter's daughter", "Grand-grandchildren", "maternal great-granddaughter", "Granddaughter-in-law", "No such relationship exists", "Unknown Relatives"},
                {"son-in-law", "Family and Family", "son's or daughter's mother-in-law", "Married Nephew", "Married Nephew", "Married Nephew", "Married Nephew", "Grandson", "Daughter's daughter", "daughter", "No such relationship exists", "Unknown Relatives"},
                {"father-in-law", "Father Tai Yue", "Mother-in-law Tai", "Boyue", "Uncle Yue", "Aunt-in-law", "Aunt-in-law", "Uncle", "Sister-in-law", "mother-in-law", "No such relationship exists", "Unknown Relatives"},
                {"mother-in-law", "Grandfather-in-law", "Grandmother-in-law", "Uncle-in-law", "Uncle-in-law", "Aunt-in-law", "Aunt-in-law", "Uncle", "Sister-in-law", "No such relationship exists", "father-in-law", "Unknown Relatives"},
                {"Uncle", "father-in-law", "mother-in-law", "Uncle", "Uncle", "Sister-in-law", "Sister-in-law", "Nephew", "Nephew", "Uncle and sister-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Uncle", "father-in-law", "mother-in-law", "Uncle", "Uncle", "Wife", "Sister-in-law", "Nephew", "Nephew", "Uncle's daughter-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Sister-in-law", "father-in-law", "mother-in-law", "Uncle", "Uncle", "Sister-in-law", "Wife", "Nephew", "if ego is female", "No such relationship exists", "someone just can be missed", "Unknown Relatives"},
                {"Sister-in-law", "father-in-law", "mother-in-law", "Uncle", "Uncle", "Wife", "Sister-in-law", "Nephew", "if ego is female", "No such relationship exists", "Little Aunt", "Unknown Relatives"},
                {"Great-grandfather", "High Grandfather", "Grandmother", "Great-grandfather", "Great Uncle and Grandfather", "Grandma Zeng", "Grandma Zeng", "grandpa", "Grandma and aunt", "Great grandmother", "No such relationship exists", "Unknown Relatives"},
                {"Great grandmother", "High Grandfather", "High Grandmother", "Uncle Great Grandfather", "Uncle Great Grandfather", "Grandmother-aunt", "Grandmother-aunt", "grandpa", "Grandma and aunt", "No such relationship exists", "Great-grandfather", "Unknown Relatives"},
                {"Grandfather", "Great-grandfather", "Great grandmother", "Grandfather", "grandpa", "Grandma and aunt", "Grandma and aunt", "Coupler", "Aunt and Aunt", "Grandmother", "No such relationship exists", "Unknown Relatives"},
                {"Grandma and aunt", "Great-grandfather", "Great grandmother", "grandpa", "Uncle-grandfather", "Grandma and aunt", "Grandma and aunt", "Aunt and uncle", "Aunts and aunts", "No such relationship exists", "paternal grandaunt's husband", "Unknown Relatives"},
                {"Great Grandfather", "Great Grandfather", "Great Grandmother", "Uncle-Great-Grandfather", "Uncle-Great-Grandfather", "Grandmother-aunt", "Grandmother-aunt", "mother's brother", "grandma", "Great Grandmother", "No such relationship exists", "Unknown Relatives"},
                {"Great Grandmother", "Grandfather Zeng", "Grandmother Zeng", "Uncle Great-Grandfather", "Uncle Great-Grandfather", "Grandmother-aunt", "Grandmother-aunt", "mother's brother", "grandma", "No such relationship exists", "Great Grandfather", "Unknown Relatives"},
                {"mother's brother", "Great Grandfather", "Great Grandmother", "mother's brother", "mother's brother", "Grandma and aunt", "grandma", "Uncle and uncle", "Uncles and Aunts", "Uncle", "No such relationship exists", "Unknown Relatives"},
                {"Grandma and aunt", "Great Grandfather", "Great Grandmother", "mother's brother", "mother's brother", "Grandma and aunt", "grandma", "Uncle and aunt", "Aunts and Aunts", "No such relationship exists", "Grandpa and Aunt", "Unknown Relatives"},
                {"Elder male cousin", "uncle", "Aunt", "Elder male cousin", "Younger male cousin", "Elder female cousin", "Younger female cousin", "son of a cousin", "daughter of a cousin", "Sister-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Younger male cousin", "uncle", "aunt", "Elder male cousin", "Younger male cousin", "Elder female cousin", "Younger female cousin", "son of a cousin", "daughter of a cousin", "Cousins and daughters-in-law", "No such relationship exists", "Unknown Relatives"},
                {"Elder female cousin", "uncle", "Aunt", "Elder male cousin", "Younger male cousin", "Elder female cousin", "Younger female cousin", "Nephew", "Nephew", "No such relationship exists", "Sister-in-law", "Unknown Relatives"},
                {"Younger female cousin", "uncle", "aunt", "Elder male cousin", "Younger male cousin", "Elder female cousin", "Younger female cousin", "Nephew", "Nephew", "No such relationship exists", "Cousin-in-law", "Unknown Relatives"},
                {"Aunt", "In-laws", "In-laws", "Married Abbot", "Married Abbot", "In-laws", "In-laws", "Elder male cousin", "Elder female cousin", "No such relationship exists", "uncle", "Unknown Relatives"},
                {"aunt", "In-laws", "In-laws", "Married Abbot", "Married Abbot", "In-laws", "In-laws", "Younger male cousin", "Younger female cousin", "No such relationship exists", "uncle", "Unknown Relatives"},
                {"Uncle and uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle and aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncles and Aunts", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and Aunts", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandpa and Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"son of a cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Don't Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Sister-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Cousins and daughters-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Sister-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Cousin-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Married Abbot", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"Cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt and Sister", "", "", "", "", "", "", "", "", "", "", ""},
                {"uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"sister of one's maternal grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle and Cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle, Cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle and aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Little Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle and Cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle, Cousin", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"mother's youngest sister-aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and cousins", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and cousins", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and cousins", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and cousins", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt and Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Little Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"nephews", "", "", "", "", "", "", "", "", "", "", ""},
                {"External Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephews and granddaughters", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandniece", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"older brother-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"Sister in Marriage", "", "", "", "", "", "", "", "", "", "", ""},
                {"Sister in Marriage", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle-grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Coupler", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt and Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt and uncle", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunts and aunts", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"paternal grandaunt's husband", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle-Great-Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle-Great-Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Great-Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother-aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother-aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew's granddaughter", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephews and grandchildren", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew's daughter-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew's son-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"In-laws", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great-grandson", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great grandchildren", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great-granddaughter", "", "", "", "", "", "", "", "", "", "", ""},
                {"Great-granddaughter", "", "", "", "", "", "", "", "", "", "", ""},
                {"grandson's wife", "", "", "", "", "", "", "", "", "", "", ""},
                {"Son-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Family and Family", "", "", "", "", "", "", "", "", "", "", ""},
                {"son's or daughter's mother-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Married Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Married Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandparents", "", "", "", "", "", "", "", "", "", "", ""},
                {"Granddaughter", "", "", "", "", "", "", "", "", "", "", ""},
                {"daughter's son-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Granddaughter-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Father Tai Yue", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandfather-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Mother-in-law Tai", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Boyue", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Yue", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Aunt-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"Nephew", "", "", "", "", "", "", "", "", "", "", ""},
                {"if ego is female", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle and sister-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle's daughter-in-law", "", "", "", "", "", "", "", "", "", "", ""},
                {"someone just can be missed", "", "", "", "", "", "", "", "", "", "", ""},
                {"Little Aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"High Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"High Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"High Grandmother", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Uncle Great Grandfather", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandma Zeng", "", "", "", "", "", "", "", "", "", "", ""},
                {"Grandmother-aunt", "", "", "", "", "", "", "", "", "", "", ""},
                {"Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives", "Unknown Relatives"}
        };
        return relationshipData;
    }
}

Next, add the following method to Controller.java:

    /**
     * Operation result: Determine whether a value exists in the row header of a two-dimensional array
     *
     * @param value A value
     * @param array 2-D Array
     * @return Return true if it exists, false otherwise
     */
    public boolean isExist(String value, String[][] array) {
        for (int i = 0; i < array.length; i++) {
            if (value.equals(array[i][0])) {
                return true;
            }
        }
        return false;
    }

Then you write the event listener for the Calculate button, so the do_countButton_event method does the following:

    @FXML
        // Event listener for the Calculate button
    void do_countButton_event(ActionEvent event) {
        String[][] relationshipData = new RelationShipData().getRelationShipData();
        String[] array = inputTextArea.getText().split("Of");
        int column = 0, row = 0;
        String resultValue = array[0];
        for (int i = 1; i < array.length; i++) {
            for (int m = 0; m < relationshipData.length; ++m) {
                if (relationshipData[m][0].equals(resultValue)) {
                    row = m;
                }
            }
            for (int n = 0; n < relationshipData[0].length; n++) {
                if (relationshipData[0][n].equals(array[i])) {
                    column = n;
                }
            }
            resultValue = relationshipData[row][column];
            if (!isExist(resultValue, relationshipData)) {
                resultValue = "Unknown Relatives";
                break;
            }
        }
        outputTextArea.setText(resultValue);
    }

The effect of clicking the Calculate button is as follows:

summary

So far, all functions have been implemented.

This is different from the previous project implementation, mainly the implementation and interface of computing and fallback functions are different.

Here is a comparative analysis:

(1) The interface of the previous project is implemented by swing, which writes more code and is more cumbersome to decorate. This project is implemented by JavaFX. JavaFX can design the interface by Scene Builder, drag controls to achieve the interface layout is more convenient, and the interface style is more useful for people who have learned the front-end, using CSS Grammar to decorate the interface is more beautiful and varied.

(2) The fallback function of the previous small project is implemented using swing's undo class, while this project customizes a stack Stack to achieve the fallback function, which is characterized by the "first in, last out".

(3) The calculation function of the previous project is to have corresponding relationship chains in order to query relationships. If dealing with complex and variable relationship chains, listing all the relationship chains is obviously a large and cumbersome task. This project uses a clever way - two-dimensional array, which uses the characteristics of two-dimensional array index to continuously traverse to obtain results.

To summarize, there may be time to think about better algorithms.

 

Search the WeChat Public Number (Java Instance Program) or scan the QR code below to follow the public number for more information.

Note: Reply in the public number background [20191128] to get the source code for this section.

394 original articles were published, 41 were praised, 90,000 visits+
Private letter follow

Keywords: Java

Added by grglaz on Sun, 19 Jan 2020 03:28:15 +0200