Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package application;
- import javafx.application.Application;
- import javafx.stage.Stage;
- import javafx.scene.Scene;
- import javafx.scene.layout.VBox;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.control.ListView;
- import java.util.ArrayList;
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) {
- try {
- VBox root = (VBox)FXMLLoader.load(getClass().getResource("Sample.fxml"));
- Scene scene = new Scene(root,400,400);
- scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
- primaryStage.setTitle("March Madness Bracket Generator");
- primaryStage.setScene(scene);
- generateData();
- primaryStage.show();
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- private ListView<String> round64 = new ListView<String>();
- static ArrayList<Team> round1 = new ArrayList<Team>();
- static ArrayList<Team> round2 = new ArrayList<Team>();
- static ArrayList<Team> round3 = new ArrayList<Team>();
- static ArrayList<Team> round4 = new ArrayList<Team>();
- static ArrayList<Team> round5 = new ArrayList<Team>();
- static ArrayList<Team> round6 = new ArrayList<Team>();
- static ArrayList<Team> round7 = new ArrayList<Team>(); //winner
- public static void main(String[] args) {
- //East //ArrayList index
- round1.add(new Team("Duke", 0.670, 1)); //0
- round1.add(new Team("North Dakota St", 0.495, 16));
- round1.add(new Team("VCU", 0.609, 8));
- round1.add(new Team("UCF", 0.606, 9));
- round1.add(new Team("Mississippi St", 0.609, 5));
- round1.add(new Team("Liberty", 0.549, 12));
- round1.add(new Team("Virginia Tech", 0.605, 4));
- round1.add(new Team("Saint Louis", 0.547, 13));
- round1.add(new Team("Maryland", 0.602, 6));
- round1.add(new Team("Belmont", 0.579, 11));
- round1.add(new Team("LSU", 0.626, 3));
- round1.add(new Team("Yale", 0.572, 14));
- round1.add(new Team("Louisville", 0.594, 7));
- round1.add(new Team("Minnesota", 0.578, 10));
- round1.add(new Team("Michigan St", 0.641, 2));
- round1.add(new Team("Bradley", 0.504, 15)); //15
- //West
- round1.add(new Team("Gonzaga", 0.645, 1));
- round1.add(new Team("Fairleigh Dickinson", 0.486, 16));
- round1.add(new Team("Syracuse", 0.581, 8));
- round1.add(new Team("Baylor", 0.565, 9));
- round1.add(new Team("Marquette", 0.599, 5));
- round1.add(new Team("Murray St", 0.581, 12));
- round1.add(new Team("Florida St", 0.634, 4));
- round1.add(new Team("Vermont", 0.562, 13));
- round1.add(new Team("Buffalo", 0.641, 6));
- round1.add(new Team("Arizona St", 0.579, 11));
- round1.add(new Team("Texas Tech", 0.619, 3));
- round1.add(new Team("Northern Ky", 0.542, 14));
- round1.add(new Team("Nevada", 0.615, 7));
- round1.add(new Team("Florida", 0.566, 10));
- round1.add(new Team("Michigan", 0.639, 2));
- round1.add(new Team("Montana", 0.551, 15)); //31
- //South
- round1.add(new Team("Virginia", 0.655, 1));
- round1.add(new Team("Gardner-Webb", 0.518, 16));
- round1.add(new Team("Mississippi", 0.561, 8));
- round1.add(new Team("Oklahoma", 0.580, 9));
- round1.add(new Team("Wisconsin", 0.606, 5));
- round1.add(new Team("Oregon", 0.575, 12));
- round1.add(new Team("Kansas St", 0.619, 4));
- round1.add(new Team("UC Irvine", 0.562, 13));
- round1.add(new Team("Villanova", 0.620, 6));
- round1.add(new Team("Saint Mary's", 0.587, 11));
- round1.add(new Team("Purdue", 0.620, 3));
- round1.add(new Team("Old Dominion", 0.562, 14));
- round1.add(new Team("Cincinnati", 0.621, 7));
- round1.add(new Team("Iowa", 0.567, 10));
- round1.add(new Team("Tennessee", 0.650, 2));
- round1.add(new Team("Colgate", 0.547, 15)); //47
- //Midwest
- round1.add(new Team("North Carolina", 0.654, 1));
- round1.add(new Team("Iona", 0.485, 16));
- round1.add(new Team("Utah St", 0.604, 8));
- round1.add(new Team("Washington", 0.609, 9));
- round1.add(new Team("Auburn", 0.612, 5));
- round1.add(new Team("New Mexico St", 0.581, 12));
- round1.add(new Team("Kansas", 0.658, 4));
- round1.add(new Team("Northeastern", 0.575, 13));
- round1.add(new Team("Iowa St", 0.600, 6));
- round1.add(new Team("Ohio St", 0.555, 11));
- round1.add(new Team("Houston", 0.650, 3));
- round1.add(new Team("Georgia St", 0.572, 14));
- round1.add(new Team("Wofford", 0.613, 7));
- round1.add(new Team("Seton Hall", 0.580, 10));
- round1.add(new Team("Kentucky", 0.644, 2));
- round1.add(new Team("Abilene Christ.", 0.525, 15)); //63
- launch(args);
- }
- private void randomizeLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
- for(int i = 0; i < lastRound.size(); i+=2) {
- int x = (int)(Math.random() * 2);
- if(x == 0) {
- currentRound.add(lastRound.get(i));
- } else {
- currentRound.add(lastRound.get(i++));
- }
- }
- }
- public void randomize() {
- //round2
- if(round2.isEmpty()) {
- randomizeLoop(round1, round2);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round1, temp);
- round2 = new ArrayList<Team>(temp);
- }
- //round3
- if(round3.isEmpty()) {
- randomizeLoop(round2, round3);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round2, temp);
- round3 = new ArrayList<Team>(temp);
- }
- //round4
- if(round4.isEmpty()) {
- randomizeLoop(round3, round4);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round3, temp);
- round4 = new ArrayList<Team>(temp);
- }
- //round5
- if(round5.isEmpty()) {
- randomizeLoop(round4, round5);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round4, temp);
- round5 = new ArrayList<Team>(temp);
- }
- //round6
- if(round6.isEmpty()) {
- randomizeLoop(round5, round6);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round5, temp);
- round6 = new ArrayList<Team>(temp);
- }
- //round7
- if(round7.isEmpty()) {
- randomizeLoop(round6, round5);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- randomizeLoop(round6, temp);
- round7 = new ArrayList<Team>(temp);
- }
- }
- private void cinderellaLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
- for(int i = 0; i < round1.size(); i += 2) {
- if(lastRound.get(i).getSeed() == lastRound.get(i++).getSeed()) {
- if(lastRound.get(i).getRating() < lastRound.get(i++).getRating()) {
- currentRound.add(lastRound.get(i));
- } else {
- currentRound.add(lastRound.get(i++));
- }
- } else {
- if(lastRound.get(i).getSeed() > lastRound.get(i++).getSeed()) {
- currentRound.add(lastRound.get(i));
- } else {
- currentRound.add(lastRound.get(i++));
- }
- }
- }
- }
- public void cinderella() {
- //round2
- if(round2.isEmpty()) {
- cinderellaLoop(round1, round2);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round1, temp);
- round2 = new ArrayList<Team>(temp);
- }
- //round3
- if(round3.isEmpty()) {
- cinderellaLoop(round2, round3);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round2, temp);
- round3 = new ArrayList<Team>(temp);
- }
- //round4
- if(round4.isEmpty()) {
- cinderellaLoop(round3, round4);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round3, temp);
- round4 = new ArrayList<Team>(temp);
- }
- //round5
- if(round5.isEmpty()) {
- cinderellaLoop(round4, round5);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round4, temp);
- round5 = new ArrayList<Team>(temp);
- }
- //round6
- if(round6.isEmpty()) {
- cinderellaLoop(round5, round6);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round5, temp);
- round6 = new ArrayList<Team>(temp);
- }
- //round7
- if(round7.isEmpty()) {
- cinderellaLoop(round6, round7);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- cinderellaLoop(round6, temp);
- round7 = new ArrayList<Team>(temp);
- }
- }
- private void topSeedLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
- for(int i = 0; i < round1.size(); i += 2) {
- if(lastRound.get(i).getSeed() == lastRound.get(i++).getSeed()) {
- if(lastRound.get(i).getRating() > lastRound.get(i++).getRating()) {
- currentRound.add(lastRound.get(i));
- } else {
- currentRound.add(lastRound.get(i++));
- }
- } else {
- if(lastRound.get(i).getSeed() < lastRound.get(i++).getSeed()) {
- currentRound.add(lastRound.get(i));
- } else {
- currentRound.add(lastRound.get(i++));
- }
- }
- }
- }
- public void topSeed() {
- //round2
- if(round2.isEmpty()) {
- topSeedLoop(round1, round2);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round1, temp);
- round2 = new ArrayList<Team>(temp);
- }
- //round3
- if(round3.isEmpty()) {
- topSeedLoop(round2, round3);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round2, temp);
- round3 = new ArrayList<Team>(temp);
- }
- //round4
- if(round4.isEmpty()) {
- topSeedLoop(round3, round4);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round3, temp);
- round4 = new ArrayList<Team>(temp);
- }
- //round5
- if(round5.isEmpty()) {
- topSeedLoop(round4, round5);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round4, temp);
- round5 = new ArrayList<Team>(temp);
- }
- //round6
- if(round6.isEmpty()) {
- topSeedLoop(round5, round6);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round5, temp);
- round6 = new ArrayList<Team>(temp);
- }
- //round7
- if(round7.isEmpty()) {
- topSeedLoop(round6, round7);
- } else {
- ArrayList<Team> temp = new ArrayList<Team>();
- topSeedLoop(round6, temp);
- round7 = new ArrayList<Team>(temp);
- }
- }
- private void generateData() {
- for(int i = 0; i < round1.size(); i++) {
- String teamName = round1.get(i).getName();
- round64.getItems().add(teamName);
- }
- }
- }
- package application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.stage.Stage;
- import java.io.IOException;
- import javafx.fxml.Initializable;
- public class Controller extends Main {
- @FXML
- private void randomizeBtn(ActionEvent event) {
- randomize();
- }
- @FXML
- private void cinderellaBtn(ActionEvent event) {
- cinderella();
- }
- @FXML
- private void topSeedBtn(ActionEvent event) {
- topSeed();
- }
- }
- package application;
- public class Team {
- private String name;
- private double rating;
- private int seed;
- public Team(String name, double rating, int seed) {
- this.name = name;
- this.rating = rating;
- this.seed = seed;
- }
- public int getSeed() {
- return seed;
- }
- public double getRating() {
- return rating;
- }
- public String getName() {
- return name;
- }
- @Override
- public String toString() {
- return name;
- }
- }
- <?xml version="1.0" encoding="UTF-8"?>
- <?import javafx.scene.control.Button?>
- <?import javafx.scene.control.ButtonBar?>
- <?import javafx.scene.control.ListView?>
- <?import javafx.scene.control.Menu?>
- <?import javafx.scene.control.MenuBar?>
- <?import javafx.scene.control.MenuItem?>
- <?import javafx.scene.control.SeparatorMenuItem?>
- <?import javafx.scene.layout.AnchorPane?>
- <?import javafx.scene.layout.VBox?>
- <VBox minHeight="-Infinity" prefHeight="800.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
- <children>
- <MenuBar VBox.vgrow="NEVER">
- <menus>
- <Menu mnemonicParsing="false" text="File">
- <items>
- <MenuItem mnemonicParsing="false" text="New" />
- <MenuItem mnemonicParsing="false" text="Open…" />
- <Menu mnemonicParsing="false" text="Open Recent" />
- <SeparatorMenuItem mnemonicParsing="false" />
- <MenuItem mnemonicParsing="false" text="Close" />
- <MenuItem mnemonicParsing="false" text="Save" />
- <MenuItem mnemonicParsing="false" text="Save As…" />
- <MenuItem mnemonicParsing="false" text="Revert" />
- <SeparatorMenuItem mnemonicParsing="false" />
- </items>
- </Menu>
- <Menu mnemonicParsing="false" text="Help">
- <items>
- <MenuItem mnemonicParsing="false" text="About" />
- <MenuItem mnemonicParsing="false" text="FAQ" />
- </items>
- </Menu>
- </menus>
- </MenuBar>
- <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
- <children>
- <ButtonBar layoutX="349.0" layoutY="721.0" prefHeight="40.0" prefWidth="277.0">
- <buttons>
- <Button mnemonicParsing="false" onAction="#randomizeBtn" text="Randomize" />
- <Button mnemonicParsing="false" onAction="#cinderellaBtn" text="Cinderella" />
- <Button mnemonicParsing="false" onAction="#topSeedBtn" text="Top Seed" />
- </buttons>
- </ButtonBar>
- <ListView layoutX="23.0" layoutY="24.0" prefHeight="686.0" prefWidth="200.0" />
- </children>
- </AnchorPane>
- </children>
- </VBox>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement