Ask Experts Questions for FREE Help !
Ask
    Shivsticker12's Avatar
    Shivsticker12 Posts: 1, Reputation: 1
    New Member
     
    #1

    Apr 5, 2015, 09:06 AM
    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);
    }
    }
    }

Check out some similar questions!

Anyone expert with java can help me writing down a program? [ 0 Answers ]

As title states, I would like someone to help me with a project for my college. Any help would be appreciated. Pm me for more info, if you are interested.

I am writing a java animation program that is just not working [ 1 Answers ]

I am writing a java animation program that creates a frame and positions a ball at the top. When you click the start button the ball is supposed to move diagonally to the bottom. However it does not move. Can anybody tell me what I am doing wrong? import java.awt.*; import...

I want the java code please [ 2 Answers ]

Write a program that ask from the user how many integers you want to read then reads the set of integers from user, and then finds and prints the sum of even valued and odd valued integers . And also count how many even was entered by user and how many odd were entered by user.

Java code [ 2 Answers ]

Please give me a simple java code for addition of two numbers here two numbers are accepted From users please give me explanation about each code


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.