# NFL 2D array standings table

• 01-03-2010, 08:05 PM
ber1023
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
• 01-03-2010, 10:55 PM
collin389
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.
• 01-03-2010, 11:02 PM
ber1023
im not even sure how i didnt see that.. thanks. do you know how to do the rest? im fully stuck

thanks
• 01-03-2010, 11:52 PM
collin389
Take a look at this code and figure out what it is doing and how you can implement it in your own code.

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.
• 01-04-2010, 04:35 AM
ber1023
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
• 01-07-2010, 05:45 AM
ber1023
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 + "%");
}
}
}