Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   Writing Java code for a Tournament (https://www.askmehelpdesk.com/showthread.php?t=810108)

  • Apr 5, 2015, 09:06 AM
    Shivsticker12
    Writing Java code for a Tournament
    Hi Everyone!

    I am working on writing a piece of code for a sports tournament, but I can't figure out how to make the input for wins and losses, move to the next team. When I go to say that I don't wish to add another win/loss, I want to have the program move on to the next team. My current thought is to have the user input what team he is adding the wins and losses to, however, I am not sure how to achieve that within Java.

    Any help is Greatly appreciated!

    Here is what I have so far:

    final int LENGTH = 15;
    String[] team = new String [LENGTH];
    int[] win = new int [LENGTH];
    int[] loss = new int [LENGTH];
    int currentSize = 0;
    int index = 0;
    String winLoss = "";
    String teamName = "";
    String inputTeam = "";
    String exitWinLoss = "";
    String exitProgram = "";
    String finalOutput = "";
    int programExit = 0;
    boolean enterScore = false;
    boolean validInput = false;
    boolean found = false;
    boolean validTeam = false;
    boolean repeatScore = true;
    boolean completeInput = false;
    int totalGames = 0;

    while (programExit == 0) {
    validTeam = false;
    while (validTeam == false) {
    if (currentSize == LENGTH) {
    JOptionPane.showMessageDialog(null, "Too many teams");
    validTeam = true;
    }

    inputTeam = JOptionPane.showInputDialog ("Please enter a new team name. \n If complete, input 'None'.");
    if (!inputTeam.equalsIgnoreCase("None")) {
    team[currentSize] = inputTeam; currentSize++;
    }
    else if (inputTeam.equalsIgnoreCase("None")) {
    validTeam = true;
    }

    }
    enterScore = false;
    while (enterScore == false) {
    found = false;
    index = 0;

    while (found == false) {
    teamName = JOptionPane.showInputDialog (null, "Enter a team name");

    while (index <= currentSize) {
    if (teamName.equalsIgnoreCase(team[index])){
    found = true;
    }
    else
    index++;
    }

    if (found == false) {
    JOptionPane.showMessageDialog(null, "Please enter a team from the list");
    }
    }
    repeatScore = true;

    while (repeatScore == true) {
    winLoss = JOptionPane.showInputDialog(null, "Enter whether 'win' or 'loss' for team " + team[index]);
    if (winLoss.equalsIgnoreCase("win")) {
    win[index] = win[index]+1; totalGames++;
    }
    else if (winLoss.equalsIgnoreCase("loss")) {
    loss[index] = loss[index]+1; totalGames++;
    }
    else if ((!winLoss.equalsIgnoreCase("win")) || !winLoss.equalsIgnoreCase("loss"))
    JOptionPane.showMessageDialog(null, "Please enter 'win' or 'loss'");


    exitWinLoss = JOptionPane.showInputDialog(null, "Add another win or loss for this team? 'yes' or 'no'");
    if (exitWinLoss.equalsIgnoreCase("no")) {
    repeatScore = false;
    index++;
    }
    if (index == currentSize) {
    enterScore = true;
    }
    }
    }
    exitProgram = JOptionPane.showInputDialog(null, "Exit the Program? 'yes' or 'no'");
    if (exitProgram.equalsIgnoreCase("yes")){
    programExit = 1;
    }
    else {
    programExit = 0;

    index = 0;
    }
    while (index < currentSize){
    if (index >= 0) {
    finalOutput = finalOutput + team[index] + "\n Wins " + win[index] + " Losses " + loss[index] + "\n";
    }
    index++;
    }
    JOptionPane.showMessageDialog(null, finalOutput + "Total Games Played: "+totalGames);
    }
    }
    }

  • All times are GMT -7. The time now is 02:02 PM.