Reading in a .txt into ArrayList for another class

By | August 11, 2018

Reading in instructions.txt from instructions.java from a comma delimited method for InstructionsController so that I may present it into a TextArea on Instructions.fxml.

Having trouble figuring out once I've read in the file, how to pass over the ArrayList to another class to successfully use that data.

Using about in handle as a test button in the InstructionsController class.

Instructions.java

public class Instructions {

private String[] identifier;

private ArrayList<String> listName;
private ArrayList<String> listDesc;



public void dataLoader() {

    String fileName = "instructions.txt";
    Scanner scan;

    /*
     * Shows working path System.out.println(newFile(".").getAbsoluteFile());
     */

    try {
        scan = new Scanner(new File(fileName));
        // Iteration rather than iterable
        while (scan.hasNext()) {
            int i = 0;
            String line = scan.nextLine();
            identifier = line.split(">");

            if(identifier[i].equals("TITLE")) {
                listName.add(identifier[i+1]);
            } else if (identifier[i].equals("DESC")) {
                listDesc.add(identifier[i+1]);
            } else if (identifier[i].equals("END")) {
                 i++;

            }

        }

        scan.close();

    } catch (FileNotFoundException exception) {
        System.err.println("Failed to open instructions");
        System.exit(1);
    }catch (Exception e) {
        e.printStackTrace();
    }
}



public ArrayList<String> getListName() {
    return listName;
}



public void setListName(ArrayList<String> listName) {
    this.listName = listName;
}



public ArrayList<String> getListDesc() {
    return listDesc;
}



public void setListDesc(ArrayList<String> listDesc) {
    this.listDesc = listDesc;
}

InstructionsController.java

public class InstructionsController implements EventHandler<ActionEvent>, Initializable {


@FXML
private Button about, constants, professionPerks, teamCilantro, mainMenu, exit;

@FXML
private AnchorPane background;

@FXML
private TextArea text;

Main main = new Main();

private List<String> name;
private List<String> desc;



@Override
public void initialize(URL location, ResourceBundle resources) {
    Instructions instructions = new Instructions();
    name = instructions.getListName();
    desc = instructions.getListDesc();
}


@FXML
public void handle(ActionEvent event) {
    Button selected = (Button) event.getSource();
    Stage stage = (Stage) selected.getScene().getWindow();

    if (selected == about)


    if(selected == mainMenu) 
        main.switchScene("fxml/Title.fxml", stage);

    if(selected == exit) 
        stage.close();

}

}

instructions.txt

TITLE> About

DESC> In Memoriam is a Role Playing Game where your head family is followed by three other struggling families in hopes to find the rumoured safe haven. The goal of the game is to achieve a high score by lasting longer and managing your supplies better than other users, or compared to your previous attempts. Luck and skill both play a factor in this game, since the user will have to manage food, medicine, clothing, and other supplies in order to make it farther and farther along the journey each time. The weather, environment, wildlife, and local population will all seemingly work against the party as they travel along. END>

TITLE> Game Mechanics DESC> - "Car" = If this supply is depleted to 0 this will terminate the game and post your score. - "Set of Clothing" = If this supply is depleted to 0, increase probability of becoming "sick". If "sick" your probability to become "seriously sick" increases every day you do not have any medicine to cure the sickness. A member that becomes "seriously sick" without medicine will become deceased. - "Ammunition" = If this supply is depleted to 0 and you're attacked by "hostile riders", this will terminate the game and post your score. **Note: having 0 bullets does not increase the likelihood of a "hostile riders" attack. ** - "Gas" = If this supply is depleted to 0, it will suspend travel until you can acquire more parts, while decaying your other supplies each day. - "Pounds of food" [cans of ration] = If this supply is depleted to 0, increase probability of becoming "hungry". If "hungry" your probability to become "starving" significantly increases every day you do not have any food to suffice the hunger. A member that becomes "starving" without food will become deceased. - "Money left" = If this supply is depleted to 0, you can't buy supplies for "Set of Clothing", "Bullets", "Wagon Parts", or "Pounds of Food". This will leave you vulnerable to any other supply that becomes depleted such as "Pounds of food" to starvation for example. - "Money left" and "Wagon Parts" = If both of these supplies become depleted you will suspend travel until you can acquire more parts and/or "Money left" to buy more parts through a random event. END>

TITLE> Constants DESC> Probability of becoming "Sick" = 1% (with "Set of Clothing")

Probability of becoming "Seriously sick" from "sick" = 0% (with "Set of Clothing")

Probability of becoming "Sick" = 1% + 4%(per day) (without "Set of Clothing")

Probability of becoming "Seriously sick" from "sick" = 1% + 8%(per day) <== Maximum days of possible survival without "Set of Clothing": 11 Days.

Probability of becoming "hungry" = 4% (with "Pounds of food")

Probability of becoming "Starving" from "hungry" = 0% (with "Pounds of food")

Probability of becoming "hungry" = 4% + 10%(per day) (without "Pounds of food")

Probability of becoming "Starving" from "hungry" = 20% + 10%(per day) (without "Pounds of food") <== Maximum days of possible survival without "Pounds of Food": 7 Days.

Probability of getting robbed by "Hostile Riders" if "Starting Cash" is up 20% = 5%

Probability of getting robbed by "Hostile Riders" if "Starting Cash" is up 50% = 12 - 15%

Probability of getting robbed by "Hostile Riders" if "Starting Cash" is up 100% = 20 - 25% END>

TITLE> Profession Perks: DESC> Investor: Starts with $150 bonus "Starting Cash" for a total of $650 "Starting Cash". Farmer: Starts with 250 "Pounds of Food" and has a perk to consume food for the party at a 75% rate compared to normal. Handyman: Significantly less likelyhood of "Wagon" breaking down. END>