Results 1 to 6 of 6
Thread: NFL 2D array standings table
- 01-03-2010, 07:05 PM #1
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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, 09:55 PM #2
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
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, 10:02 PM #3
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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, 10:52 PM #4
Senior Member
- Join Date
- Nov 2009
- Posts
- 235
- Rep Power
- 4
Take a look at this code and figure out what it is doing and how you can implement it in your own code.
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.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"); } } }
- 01-04-2010, 03:35 AM #5
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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, 04:45 AM #6
Member
- Join Date
- Dec 2009
- Posts
- 10
- Rep Power
- 0
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
-
Drawing 3d graph from array table
By Mekonom in forum Java 2DReplies: 3Last Post: 12-26-2009, 09:42 AM -
Convert Char Array to String Array
By Mayur in forum New To JavaReplies: 8Last Post: 10-12-2009, 11:41 AM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM -
Table Help
By CoOlbOyCoOl in forum NetBeansReplies: 1Last Post: 05-06-2007, 04:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks