Results 1 to 6 of 6
  1. #1
    ber1023 is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Exclamation NFL 2D array standings table

    good day, i am a rookie when it comes to java and im just basicaly messing around for fun. Im trying to make a program where you have 4 teams and using 2D array you enter there wins and losses, it calculates the win pct and sorts them in win pct order. just like the NFL standings. my code so far im sure isnt efficiecnt or anywhere near correct i am simply a major begginner and basicaly have no idea what im doing. I have a book on this but im stuck and dont no where to go from here.

    import java.lang.Integer;

    public class FootBall
    {

    public FootBall()
    {
    table = new String[ROWS][COLUMNS];
    for(int i = 0; i < ROWS; i++)
    for(int j = 0; j < COLUMNS; j++)
    table[i][j] = " ";
    }
    /*public String getLosses()
    {
    return
    }
    public String getPercent()
    {
    return
    }
    public String getWin()
    {
    return
    }
    public String getName()
    {
    return
    }*/
    public void result(int win, int loss, String team)
    {
    if(table[win][loss].equals(""))
    {
    table[win][loss] = team;
    }
    }
    public void wins(String x)
    {
    String table[0][0] = "x";
    }

    public String toStringR()
    {
    String r = "Ravens";
    for(int i = 0; i < ROWS; i++)
    {
    r = r+"|";
    for(int j =0; j < COLUMNS; j++)
    {
    r = r + table[i][j];
    }
    r = r + "|\n";
    }
    return r;
    }
    public String toStringB()
    {
    String b = "Bengals";
    for(int i = 0; i < ROWS; i++)
    {
    b = b+"|";
    for(int j =0; j < COLUMNS; j++)
    {
    b = b + table[i][j];
    }
    b = b + "|\n";
    }
    return b;
    }
    public String toStringC()
    {
    String c = "Cleveland";
    for(int i = 0; i < ROWS; i++)
    {
    c = c+"|";
    for(int j =0; j < COLUMNS; j++)
    {
    c = c + table[i][j];
    }
    c = c + "|\n";
    }
    return c;
    }
    public String toStringS()
    {
    String s = "Steelers";
    for(int i = 0; i < ROWS; i++)
    {
    s = s+"|";
    for(int j =0; j < COLUMNS; j++)
    {
    s = s + table[i][j];
    }
    s = s + "|\n";
    }
    return s;
    }

    private static final int ROWS = 1;
    private static final int COLUMNS = 2;
    private String[][] table;



    thats what i have. my individual tables show up but i cant write a tester. i cant even figure out how to enter numbers in them. Can someone lead me in the right direction? or try finishing it.. im getting frusterated!

    thanks a lot

  2. #2
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Why do you have so many toString() methods? You only need one since you are printing out the exact same thing in all of them except the name. If you really need the name, use pass it as a parameter, or just print the name before you all the toString() method.

  3. #3
    ber1023 is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Default

    im not even sure how i didnt see that.. thanks. do you know how to do the rest? im fully stuck

    thanks

  4. #4
    collin389 is offline Senior Member
    Join Date
    Nov 2009
    Posts
    235
    Rep Power
    6

    Default

    Take a look at this code and figure out what it is doing and how you can implement it in your own code.

    Java Code:
       import java.util.Scanner;
        
        public class arrayInput
          {
          static int TEAMS = 4;
           public static void main(String args[])
             {
             Scanner input = new Scanner(System.in);
             int[][] table = new int[TEAMS][2];
             String[] Teams = {"Ravens", "Bengals", "Cleveland", "Steelers" };
             System.out.println("Enter Win loss for each team: ");
             System.out.println("Win/Loss");
             for(int i=0; i<TEAMS; i++)
                {
                System.out.print(Teams[i] + ": ");
                Scanner s = new Scanner(input.next()).useDelimiter("/");
                table[i][0] = s.nextInt();
                table[i][1] = s.nextInt();
                }
                
             for (int[] a : table)
                {
                for(int b : a)
                   {
                   System.out.print(b + " ");
                   }
                System.out.print("\n");
                }
             }
          }
    When you input you have to type ex. 1/2 2/3 4/5 3/2 the first number is the wins the second is the losses. This program takes what you input, puts it into a 2d array, and prints it out.

  5. #5
    ber1023 is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Default

    thanks. im just trying to figure out how to get the win pct and the names of the teams next to the printed wins/losses. this deffinitly helps me out

  6. #6
    ber1023 is offline Member
    Join Date
    Dec 2009
    Posts
    10
    Rep Power
    0

    Default

    Here is the code i have, im sure my sorting isnt efficient but i am able to get the winner if you run this code you will see that. I am printing them off in order of there win pct but i am having trouble thinking through how to get the 2nd and 3rd teams. can anyone help pleasE? thanks


    import java.util.Scanner;
    import java.lang.String;

    public class FootBallTester
    {
    static int TEAMS = 4;
    static int g=1;
    public static void main(String args[])
    {

    FootBall bob = new FootBall();
    Scanner input = new Scanner(System.in);
    double[][] table = new double[TEAMS][3];
    String[] Teams = {"Ravens", "Bengals", "Cleveland", "Steelers" };
    System.out.println("Enter Win loss for each team: ");
    System.out.println("Win-Loss");
    for(int i=0; i<TEAMS; i++)
    {

    System.out.print(Teams[i] + ": ");
    Scanner s = new Scanner(input.next()).useDelimiter("-");
    table[i][0] = s.nextInt();
    table[i][1] = s.nextInt();
    table[i][2] = (table[i][0]/(table[i][0]+table[i][1]));
    System.out.println("Wins: " + table[i][0] + " "+ "Losses: " + table[i][1] + " "+ "Win PCT: " + table[i][2]+"%");
    }
    for(int i = 0; i<1; i++)
    {
    String team = "Ravens";
    double winner = table[0][2];
    if(winner < table[1][2])
    {
    double newwinner = table[1][2];
    winner = newwinner;
    if(newwinner == table[1][2])
    {
    String newteam = Teams[1];
    team = newteam;
    }
    }
    if(winner < table[2][2])
    {
    double newwinner = table[2][2];
    winner = newwinner;
    if(newwinner == table[2][2])
    {
    String newteam = Teams[2];
    team = newteam;
    }
    }
    if(winner < table[3][2])
    {
    double newwinner = table[3][2];
    winner = newwinner;
    if(newwinner == table[3][2])
    {
    String newteam = Teams[3];
    team = newteam;
    }
    }
    System.out.print(team +" "+ winner + "%");


    double second = table[1][2];
    String team2="Bengals";
    if(second < winner)
    {
    if(second == table[1][2])
    {
    String theeam = Teams[1];
    team2 = theeam;
    }
    }
    System.out.print("\n"+ team2 +" "+ second + "%");
    }
    }
    }

Similar Threads

  1. Drawing 3d graph from array table
    By Mekonom in forum Java 2D
    Replies: 3
    Last Post: 12-26-2009, 10:42 AM
  2. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 12:41 PM
  3. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 10:12 AM
  4. Replies: 1
    Last Post: 03-31-2009, 07:40 AM
  5. Table Help
    By CoOlbOyCoOl in forum NetBeans
    Replies: 1
    Last Post: 05-06-2007, 05:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •