Advertisement
Guest User

March madness generator

a guest
Jun 3rd, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.58 KB | None | 0 0
  1. package application;
  2.  
  3. import javafx.application.Application;
  4. import javafx.stage.Stage;
  5. import javafx.scene.Scene;
  6. import javafx.scene.layout.VBox;
  7. import javafx.fxml.FXMLLoader;
  8.  
  9. import javafx.scene.control.ListView;
  10.  
  11. import java.util.ArrayList;
  12.  
  13.  
  14. public class Main extends Application {
  15.  
  16. @Override
  17. public void start(Stage primaryStage) {
  18. try {
  19. VBox root = (VBox)FXMLLoader.load(getClass().getResource("Sample.fxml"));
  20. Scene scene = new Scene(root,400,400);
  21. scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
  22. primaryStage.setTitle("March Madness Bracket Generator");
  23. primaryStage.setScene(scene);
  24.  
  25. generateData();
  26.  
  27. primaryStage.show();
  28.  
  29. } catch(Exception e) {
  30. e.printStackTrace();
  31. }
  32. }
  33.  
  34.  
  35. private ListView<String> round64 = new ListView<String>();
  36.  
  37. static ArrayList<Team> round1 = new ArrayList<Team>();
  38. static ArrayList<Team> round2 = new ArrayList<Team>();
  39. static ArrayList<Team> round3 = new ArrayList<Team>();
  40. static ArrayList<Team> round4 = new ArrayList<Team>();
  41. static ArrayList<Team> round5 = new ArrayList<Team>();
  42. static ArrayList<Team> round6 = new ArrayList<Team>();
  43.  
  44. static ArrayList<Team> round7 = new ArrayList<Team>(); //winner
  45.  
  46.  
  47. public static void main(String[] args) {
  48.  
  49. //East //ArrayList index
  50. round1.add(new Team("Duke", 0.670, 1)); //0
  51. round1.add(new Team("North Dakota St", 0.495, 16));
  52. round1.add(new Team("VCU", 0.609, 8));
  53. round1.add(new Team("UCF", 0.606, 9));
  54. round1.add(new Team("Mississippi St", 0.609, 5));
  55. round1.add(new Team("Liberty", 0.549, 12));
  56. round1.add(new Team("Virginia Tech", 0.605, 4));
  57. round1.add(new Team("Saint Louis", 0.547, 13));
  58. round1.add(new Team("Maryland", 0.602, 6));
  59. round1.add(new Team("Belmont", 0.579, 11));
  60. round1.add(new Team("LSU", 0.626, 3));
  61. round1.add(new Team("Yale", 0.572, 14));
  62. round1.add(new Team("Louisville", 0.594, 7));
  63. round1.add(new Team("Minnesota", 0.578, 10));
  64. round1.add(new Team("Michigan St", 0.641, 2));
  65. round1.add(new Team("Bradley", 0.504, 15)); //15
  66.  
  67. //West
  68. round1.add(new Team("Gonzaga", 0.645, 1));
  69. round1.add(new Team("Fairleigh Dickinson", 0.486, 16));
  70. round1.add(new Team("Syracuse", 0.581, 8));
  71. round1.add(new Team("Baylor", 0.565, 9));
  72. round1.add(new Team("Marquette", 0.599, 5));
  73. round1.add(new Team("Murray St", 0.581, 12));
  74. round1.add(new Team("Florida St", 0.634, 4));
  75. round1.add(new Team("Vermont", 0.562, 13));
  76. round1.add(new Team("Buffalo", 0.641, 6));
  77. round1.add(new Team("Arizona St", 0.579, 11));
  78. round1.add(new Team("Texas Tech", 0.619, 3));
  79. round1.add(new Team("Northern Ky", 0.542, 14));
  80. round1.add(new Team("Nevada", 0.615, 7));
  81. round1.add(new Team("Florida", 0.566, 10));
  82. round1.add(new Team("Michigan", 0.639, 2));
  83. round1.add(new Team("Montana", 0.551, 15)); //31
  84.  
  85. //South
  86. round1.add(new Team("Virginia", 0.655, 1));
  87. round1.add(new Team("Gardner-Webb", 0.518, 16));
  88. round1.add(new Team("Mississippi", 0.561, 8));
  89. round1.add(new Team("Oklahoma", 0.580, 9));
  90. round1.add(new Team("Wisconsin", 0.606, 5));
  91. round1.add(new Team("Oregon", 0.575, 12));
  92. round1.add(new Team("Kansas St", 0.619, 4));
  93. round1.add(new Team("UC Irvine", 0.562, 13));
  94. round1.add(new Team("Villanova", 0.620, 6));
  95. round1.add(new Team("Saint Mary's", 0.587, 11));
  96. round1.add(new Team("Purdue", 0.620, 3));
  97. round1.add(new Team("Old Dominion", 0.562, 14));
  98. round1.add(new Team("Cincinnati", 0.621, 7));
  99. round1.add(new Team("Iowa", 0.567, 10));
  100. round1.add(new Team("Tennessee", 0.650, 2));
  101. round1.add(new Team("Colgate", 0.547, 15)); //47
  102.  
  103. //Midwest
  104. round1.add(new Team("North Carolina", 0.654, 1));
  105. round1.add(new Team("Iona", 0.485, 16));
  106. round1.add(new Team("Utah St", 0.604, 8));
  107. round1.add(new Team("Washington", 0.609, 9));
  108. round1.add(new Team("Auburn", 0.612, 5));
  109. round1.add(new Team("New Mexico St", 0.581, 12));
  110. round1.add(new Team("Kansas", 0.658, 4));
  111. round1.add(new Team("Northeastern", 0.575, 13));
  112. round1.add(new Team("Iowa St", 0.600, 6));
  113. round1.add(new Team("Ohio St", 0.555, 11));
  114. round1.add(new Team("Houston", 0.650, 3));
  115. round1.add(new Team("Georgia St", 0.572, 14));
  116. round1.add(new Team("Wofford", 0.613, 7));
  117. round1.add(new Team("Seton Hall", 0.580, 10));
  118. round1.add(new Team("Kentucky", 0.644, 2));
  119. round1.add(new Team("Abilene Christ.", 0.525, 15)); //63
  120.  
  121. launch(args);
  122.  
  123. }
  124.  
  125.  
  126. private void randomizeLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
  127. for(int i = 0; i < lastRound.size(); i+=2) {
  128. int x = (int)(Math.random() * 2);
  129. if(x == 0) {
  130. currentRound.add(lastRound.get(i));
  131. } else {
  132. currentRound.add(lastRound.get(i++));
  133. }
  134. }
  135. }
  136.  
  137. public void randomize() {
  138.  
  139. //round2
  140. if(round2.isEmpty()) {
  141. randomizeLoop(round1, round2);
  142. } else {
  143. ArrayList<Team> temp = new ArrayList<Team>();
  144. randomizeLoop(round1, temp);
  145.  
  146. round2 = new ArrayList<Team>(temp);
  147. }
  148.  
  149. //round3
  150. if(round3.isEmpty()) {
  151. randomizeLoop(round2, round3);
  152. } else {
  153. ArrayList<Team> temp = new ArrayList<Team>();
  154. randomizeLoop(round2, temp);
  155.  
  156. round3 = new ArrayList<Team>(temp);
  157. }
  158.  
  159. //round4
  160. if(round4.isEmpty()) {
  161. randomizeLoop(round3, round4);
  162. } else {
  163. ArrayList<Team> temp = new ArrayList<Team>();
  164. randomizeLoop(round3, temp);
  165.  
  166. round4 = new ArrayList<Team>(temp);
  167. }
  168.  
  169. //round5
  170. if(round5.isEmpty()) {
  171. randomizeLoop(round4, round5);
  172. } else {
  173. ArrayList<Team> temp = new ArrayList<Team>();
  174. randomizeLoop(round4, temp);
  175.  
  176. round5 = new ArrayList<Team>(temp);
  177. }
  178.  
  179. //round6
  180. if(round6.isEmpty()) {
  181. randomizeLoop(round5, round6);
  182. } else {
  183. ArrayList<Team> temp = new ArrayList<Team>();
  184. randomizeLoop(round5, temp);
  185.  
  186. round6 = new ArrayList<Team>(temp);
  187. }
  188.  
  189. //round7
  190. if(round7.isEmpty()) {
  191. randomizeLoop(round6, round5);
  192. } else {
  193. ArrayList<Team> temp = new ArrayList<Team>();
  194. randomizeLoop(round6, temp);
  195.  
  196. round7 = new ArrayList<Team>(temp);
  197. }
  198.  
  199.  
  200. }
  201.  
  202. private void cinderellaLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
  203. for(int i = 0; i < round1.size(); i += 2) {
  204. if(lastRound.get(i).getSeed() == lastRound.get(i++).getSeed()) {
  205. if(lastRound.get(i).getRating() < lastRound.get(i++).getRating()) {
  206. currentRound.add(lastRound.get(i));
  207. } else {
  208. currentRound.add(lastRound.get(i++));
  209. }
  210.  
  211. } else {
  212. if(lastRound.get(i).getSeed() > lastRound.get(i++).getSeed()) {
  213. currentRound.add(lastRound.get(i));
  214. } else {
  215. currentRound.add(lastRound.get(i++));
  216. }
  217. }
  218. }
  219. }
  220.  
  221. public void cinderella() {
  222.  
  223. //round2
  224. if(round2.isEmpty()) {
  225. cinderellaLoop(round1, round2);
  226. } else {
  227. ArrayList<Team> temp = new ArrayList<Team>();
  228. cinderellaLoop(round1, temp);
  229.  
  230. round2 = new ArrayList<Team>(temp);
  231. }
  232.  
  233. //round3
  234. if(round3.isEmpty()) {
  235. cinderellaLoop(round2, round3);
  236. } else {
  237. ArrayList<Team> temp = new ArrayList<Team>();
  238. cinderellaLoop(round2, temp);
  239.  
  240. round3 = new ArrayList<Team>(temp);
  241. }
  242.  
  243. //round4
  244. if(round4.isEmpty()) {
  245. cinderellaLoop(round3, round4);
  246. } else {
  247. ArrayList<Team> temp = new ArrayList<Team>();
  248. cinderellaLoop(round3, temp);
  249.  
  250. round4 = new ArrayList<Team>(temp);
  251. }
  252.  
  253. //round5
  254. if(round5.isEmpty()) {
  255. cinderellaLoop(round4, round5);
  256. } else {
  257. ArrayList<Team> temp = new ArrayList<Team>();
  258. cinderellaLoop(round4, temp);
  259.  
  260. round5 = new ArrayList<Team>(temp);
  261. }
  262.  
  263. //round6
  264. if(round6.isEmpty()) {
  265. cinderellaLoop(round5, round6);
  266. } else {
  267. ArrayList<Team> temp = new ArrayList<Team>();
  268. cinderellaLoop(round5, temp);
  269.  
  270. round6 = new ArrayList<Team>(temp);
  271. }
  272.  
  273. //round7
  274. if(round7.isEmpty()) {
  275. cinderellaLoop(round6, round7);
  276. } else {
  277. ArrayList<Team> temp = new ArrayList<Team>();
  278. cinderellaLoop(round6, temp);
  279.  
  280. round7 = new ArrayList<Team>(temp);
  281. }
  282.  
  283. }
  284.  
  285.  
  286. private void topSeedLoop(ArrayList<Team> lastRound, ArrayList<Team> currentRound) {
  287. for(int i = 0; i < round1.size(); i += 2) {
  288. if(lastRound.get(i).getSeed() == lastRound.get(i++).getSeed()) {
  289. if(lastRound.get(i).getRating() > lastRound.get(i++).getRating()) {
  290. currentRound.add(lastRound.get(i));
  291. } else {
  292. currentRound.add(lastRound.get(i++));
  293. }
  294.  
  295. } else {
  296. if(lastRound.get(i).getSeed() < lastRound.get(i++).getSeed()) {
  297. currentRound.add(lastRound.get(i));
  298. } else {
  299. currentRound.add(lastRound.get(i++));
  300. }
  301. }
  302. }
  303. }
  304.  
  305. public void topSeed() {
  306.  
  307. //round2
  308. if(round2.isEmpty()) {
  309. topSeedLoop(round1, round2);
  310. } else {
  311. ArrayList<Team> temp = new ArrayList<Team>();
  312. topSeedLoop(round1, temp);
  313.  
  314. round2 = new ArrayList<Team>(temp);
  315. }
  316.  
  317. //round3
  318. if(round3.isEmpty()) {
  319. topSeedLoop(round2, round3);
  320. } else {
  321. ArrayList<Team> temp = new ArrayList<Team>();
  322. topSeedLoop(round2, temp);
  323.  
  324. round3 = new ArrayList<Team>(temp);
  325. }
  326.  
  327. //round4
  328. if(round4.isEmpty()) {
  329. topSeedLoop(round3, round4);
  330. } else {
  331. ArrayList<Team> temp = new ArrayList<Team>();
  332. topSeedLoop(round3, temp);
  333.  
  334. round4 = new ArrayList<Team>(temp);
  335. }
  336.  
  337. //round5
  338. if(round5.isEmpty()) {
  339. topSeedLoop(round4, round5);
  340. } else {
  341. ArrayList<Team> temp = new ArrayList<Team>();
  342. topSeedLoop(round4, temp);
  343.  
  344. round5 = new ArrayList<Team>(temp);
  345. }
  346.  
  347. //round6
  348. if(round6.isEmpty()) {
  349. topSeedLoop(round5, round6);
  350. } else {
  351. ArrayList<Team> temp = new ArrayList<Team>();
  352. topSeedLoop(round5, temp);
  353.  
  354. round6 = new ArrayList<Team>(temp);
  355. }
  356.  
  357. //round7
  358. if(round7.isEmpty()) {
  359. topSeedLoop(round6, round7);
  360. } else {
  361. ArrayList<Team> temp = new ArrayList<Team>();
  362. topSeedLoop(round6, temp);
  363.  
  364. round7 = new ArrayList<Team>(temp);
  365. }
  366.  
  367. }
  368.  
  369.  
  370. private void generateData() {
  371. for(int i = 0; i < round1.size(); i++) {
  372. String teamName = round1.get(i).getName();
  373. round64.getItems().add(teamName);
  374. }
  375. }
  376.  
  377. }
  378.  
  379.  
  380.  
  381.  
  382. package application;
  383.  
  384. import javafx.event.ActionEvent;
  385. import javafx.event.EventHandler;
  386. import javafx.fxml.FXML;
  387. import javafx.fxml.FXMLLoader;
  388. import javafx.scene.Node;
  389. import javafx.scene.Parent;
  390. import javafx.scene.Scene;
  391. import javafx.scene.control.Button;
  392. import javafx.stage.Stage;
  393. import java.io.IOException;
  394. import javafx.fxml.Initializable;
  395.  
  396. public class Controller extends Main {
  397.  
  398. @FXML
  399. private void randomizeBtn(ActionEvent event) {
  400. randomize();
  401. }
  402.  
  403. @FXML
  404. private void cinderellaBtn(ActionEvent event) {
  405. cinderella();
  406. }
  407.  
  408. @FXML
  409. private void topSeedBtn(ActionEvent event) {
  410. topSeed();
  411. }
  412.  
  413. }
  414.  
  415.  
  416.  
  417. package application;
  418.  
  419.  
  420. public class Team {
  421.  
  422. private String name;
  423. private double rating;
  424. private int seed;
  425.  
  426. public Team(String name, double rating, int seed) {
  427. this.name = name;
  428. this.rating = rating;
  429. this.seed = seed;
  430. }
  431.  
  432. public int getSeed() {
  433. return seed;
  434. }
  435.  
  436. public double getRating() {
  437. return rating;
  438. }
  439.  
  440. public String getName() {
  441. return name;
  442. }
  443.  
  444. @Override
  445. public String toString() {
  446. return name;
  447. }
  448.  
  449.  
  450. }
  451.  
  452.  
  453.  
  454.  
  455. <?xml version="1.0" encoding="UTF-8"?>
  456.  
  457. <?import javafx.scene.control.Button?>
  458. <?import javafx.scene.control.ButtonBar?>
  459. <?import javafx.scene.control.ListView?>
  460. <?import javafx.scene.control.Menu?>
  461. <?import javafx.scene.control.MenuBar?>
  462. <?import javafx.scene.control.MenuItem?>
  463. <?import javafx.scene.control.SeparatorMenuItem?>
  464. <?import javafx.scene.layout.AnchorPane?>
  465. <?import javafx.scene.layout.VBox?>
  466.  
  467. <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">
  468. <children>
  469. <MenuBar VBox.vgrow="NEVER">
  470. <menus>
  471. <Menu mnemonicParsing="false" text="File">
  472. <items>
  473. <MenuItem mnemonicParsing="false" text="New" />
  474. <MenuItem mnemonicParsing="false" text="Open…" />
  475. <Menu mnemonicParsing="false" text="Open Recent" />
  476. <SeparatorMenuItem mnemonicParsing="false" />
  477. <MenuItem mnemonicParsing="false" text="Close" />
  478. <MenuItem mnemonicParsing="false" text="Save" />
  479. <MenuItem mnemonicParsing="false" text="Save As…" />
  480. <MenuItem mnemonicParsing="false" text="Revert" />
  481. <SeparatorMenuItem mnemonicParsing="false" />
  482. </items>
  483. </Menu>
  484. <Menu mnemonicParsing="false" text="Help">
  485. <items>
  486. <MenuItem mnemonicParsing="false" text="About" />
  487. <MenuItem mnemonicParsing="false" text="FAQ" />
  488. </items>
  489. </Menu>
  490. </menus>
  491. </MenuBar>
  492. <AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
  493. <children>
  494. <ButtonBar layoutX="349.0" layoutY="721.0" prefHeight="40.0" prefWidth="277.0">
  495. <buttons>
  496. <Button mnemonicParsing="false" onAction="#randomizeBtn" text="Randomize" />
  497. <Button mnemonicParsing="false" onAction="#cinderellaBtn" text="Cinderella" />
  498. <Button mnemonicParsing="false" onAction="#topSeedBtn" text="Top Seed" />
  499. </buttons>
  500. </ButtonBar>
  501. <ListView layoutX="23.0" layoutY="24.0" prefHeight="686.0" prefWidth="200.0" />
  502. </children>
  503. </AnchorPane>
  504. </children>
  505. </VBox>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement