Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.*;
- import javax.swing.*;
- public class Main {
- public static void main(String[] args) throws IOException {
- NbaDraft nbaDraft1 = new NbaDraft(); // Create object of class w/ methods to help create draft
- ArrayList<String> nbaTeams = new ArrayList<>(); // create ArrayList to hold all 30 NBA teams
- nbaTeams.addAll(nbaDraft1.addNbaTeams()); // call method to add teams in alphabetical order
- ArrayList<String> draftOrder = new ArrayList<>(); // create ArrayList to hold teams in the order they'll pick
- draftOrder.addAll(nbaDraft1.createDraftOrder(nbaTeams)); // create order from team list, add to order list
- nbaDraft1.printDraftOrder(draftOrder); // print draft order
- ArrayList<String> draftPlayers = new ArrayList<>(); // create ArrayList to hold players the teams pick
- draftPlayers.addAll(nbaDraft1.draftPlayers(draftOrder)); // prompt for players, add to list
- ArrayList<String> draft1 = new ArrayList<>();
- draft1.addAll(nbaDraft1.createDraft(draftOrder, draftPlayers));
- // create ArrayList to hold draft info (teams in proper order associated w/ players they drafted)
- // nbaDraft1.printDraft(draft1); // print draft (Un-comment code in order to print draft instead of
- // reading from text file to be created below)
- CreateDraftFile draft = new CreateDraftFile();
- // create object of class w/ methods to write and read file that'll hold your particular draft
- draft.writeToFile(draft1); // call method to write your draft to a text file
- System.out.println();
- draft.readDraftFile(); // call method read and print the info on file
- }
- }
- public class NbaDraft {
- private ArrayList<String> list;
- private ArrayList<String> order;
- private ArrayList<String> picks;
- private ArrayList<String> draft;
- private String rounds;
- private int numRounds;
- public NbaDraft() {
- list = new ArrayList<>();
- order = new ArrayList<>();
- picks = new ArrayList<>();
- draft = new ArrayList<>();
- numRounds = 0;
- }
- public ArrayList<String> addNbaTeams(){
- String teams = ("Atlanta Hawks,Boston Celtics,Brooklyn Nets,Charlotte Hornets,Chicago Bulls," +
- "Cleveland Cavaliers,Dallas Mavericks,Denver Nuggets,Detroit Pistons,Golden State Warriors" +
- ",Houston Rockets,Indiana Pacers,Los Angeles Clippers,Los Angeles Lakers,Memphis Grizzlies" +
- ",Miami Heat,Milwaukee Bucks,Minnesota Timberwolves,New Orleans Pelicans,New York Knicks," +
- "Oklahoma City Thunder,Orlando Magic,Philadelphia 76ers,Phoenix Suns,Portland Trailblazers" +
- ",Sacramento Kings,San Antonio Spurs,Toronto Raptors,Utah Jazz,Washington Wizards");
- String[] data = teams.split(",");
- list.addAll(Arrays.asList(data));
- return list;
- }
- public ArrayList<String> createDraftOrder(ArrayList<String> teams){
- while (numRounds == 0) {
- try {
- rounds = (JOptionPane.showInputDialog("How many rounds will the draft have? (1-5)"));
- numRounds = Integer.parseInt(rounds);
- } catch (NumberFormatException e) {
- JOptionPane.showMessageDialog(null, "Wrong data type, please enter an integer");
- }
- }
- Collections.shuffle(teams);
- order.addAll(teams);
- for (int i = 0; i < (numRounds - 1); ++i) {
- Collections.reverse(teams);
- order.addAll(teams);
- }
- return order;
- }
- public void printDraftOrder(ArrayList<String> list){
- if(numRounds == 0){
- System.out.println("Draft cancelled!");
- }
- if(numRounds>=1) {
- System.out.println("nRound 1: n");
- for (int x = 0; x < 30; ++x) {
- System.out.println((x + 1) + ". " + list.get(x));
- }
- }
- if(numRounds >= 2) {
- System.out.println("nRound 2: n");
- for (int x = 30; x < 60; ++x) {
- System.out.println((x + 1) + ". " + list.get(x));
- }
- }
- if(numRounds >= 3) {
- System.out.println("nRound 3: n");
- for (int x = 60; x < 90; ++x) {
- System.out.println((x + 1) + ". " + list.get(x));
- }
- }
- if(numRounds >= 4) {
- System.out.println("nRound 4: n");
- for (int x = 90; x < 120; ++x) {
- System.out.println((x + 1) + ". " + list.get(x));
- }
- }
- if(numRounds == 5) {
- System.out.println("nRound 5: n");
- for (int x = 120; x < 150; ++x) {
- System.out.println((x + 1) + ". " + list.get(x));
- }
- }
- }
- public ArrayList<String> draftPlayers(ArrayList<String> players){
- for (int i=0; i<players.size(); ++i){
- String pick = JOptionPane.showInputDialog("Pick #" + (i+1) + ": nEnter your draft selection for the " + players.get(i));
- if(pick != null){
- picks.add(pick);
- }
- else {
- break;
- }
- }
- return picks;
- }
- public ArrayList<String> createDraft(ArrayList<String> order, ArrayList<String> picks) {
- for (int x=0; x<picks.size(); ++x) {
- if((order.get(x)!= null) && (picks.get(x)!= null)) {
- draft.add((x + 1) + ". " + order.get(x) + ": " + picks.get(x));
- }
- }
- return draft;
- }
- public void printDraft(ArrayList<String> draft){
- if (numRounds == 0) {
- System.out.println("Draft cancelled!");
- }
- if (numRounds >= 1) {
- System.out.println("nRound 1: n");
- for (int x = 0; x < 30; ++x) {
- System.out.println(draft.get(x));
- }
- }
- if (numRounds >= 2) {
- System.out.println("nRound 2: n");
- for (int x = 30; x < 60; ++x) {
- System.out.println(draft.get(x));
- }
- }
- if (numRounds >= 3) {
- System.out.println("nRound 3: n");
- for (int x = 60; x < 90; ++x) {
- System.out.println(draft.get(x));
- }
- }
- if (numRounds >= 4) {
- System.out.println("nRound 4: n");
- for (int x = 90; x < 120; ++x) {
- System.out.println(draft.get(x));
- }
- }
- if (numRounds == 5) {
- System.out.println("nRound 5: n");
- for (int x = 120; x < 150; ++x) {
- System.out.println(draft.get(x));
- }
- }
- }
- }
- public class CreateDraftFile {
- private Writer draftFile;
- private InputStream inDraft;
- private BufferedReader draft;
- private File file;
- public CreateDraftFile() {
- try {
- String fileName = JOptionPane.showInputDialog("Input file name: ");
- String filePath = JOptionPane.showInputDialog("Input file path (aside from file name, end with \\): ");
- file = new File(filePath + fileName + ".txt");
- draftFile = new BufferedWriter(new FileWriter(file));
- inDraft = new FileInputStream(file);
- draft = new BufferedReader(new InputStreamReader(inDraft));
- }
- catch (IOException e){
- e.getMessage();
- }
- }
- public void writeToFile(ArrayList<String> draftInfo) throws IOException {
- try {
- String separator = System.getProperty("line.separator");
- for (int i=0; i<draftInfo.size(); ++i) {
- draftFile.write(draftInfo.get(i) + separator);
- }
- }
- catch (IOException e){
- e.getMessage();
- }
- draftFile.close();
- }
- public void readDraftFile() throws IOException {
- String s;
- while((s = draft.readLine())!= null){
- System.out.println(s);
- }
- draft.close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement