简体   繁体   中英

how can i do the calculation of score with java?

I have a homework assignment... it says:

Your need to show 5 soccer teams from Colombian league on a menu. Remember that each teams plays 4 games. You must ask the score obtained in the 4 games against each team (cycles) and so on with other teams.

Marcador equipo1 vs equipo2 = ?
Marcador equipo1 vs equipo3 = ?
Marcador equipo1 vs equipo4 = ?
Marcador equipo1 vs equipo5 = ?

calculate at the end according to the table of the first 3 places, and show requested result.

it is necessary to know the position (1, 2 and 3) of soccer championship, indicating at the end the name of the team, the position occupied, and the number of points calculated as follows:

if tied, 1 point is added.
if win, 3 points are added.
if lose, 1 point is deducted.
This is what I did but I'm not sure how to store the points, do the calculations and then display them. This is the code:

public static void main(String arg[]){
            
    String [] equipos = {"Atletico Nacional","Deportes Quindio", "Millonarios F.C", "Jr de Barranquilla", "America de Cali"};

    int [][] tabla;
    int [] puntos;
    int gana = 3;
    int pierde = -1;
    int empata = 1;
            
    Scanner sc = new Scanner(System.in);
            
    System.out.println(" _________________________________________________");
    System.out.println("|                                                 |");
    System.out.println("|                      MENU                       |");
    System.out.println("|_________________________________________________|");
    System.out.println("|                                                 |"); 
    System.out.println("| Equipos                                         |");
    System.out.println("|                                                 |");
    System.out.println("| 1. Atletico nacional                            |");       
    System.out.println("| 2. Deportes Quindio                             |");
    System.out.println("| 3. Jr de barranquilla                           |");
    System.out.println("| 4. Millonarios F.C                              |");
    System.out.println("| 5. America de cali                              |");
    System.out.println("|_________________________________________________|");
            
    System.out.println("Inicio del juego...");
    System.out.println();
   
    tabla = new int[5][5];
      for (int i = 0; i < 5; i++){
                for(int u = 0; u < 5; u++){
                    if(i==u){
                        tabla[i][u] = -2;
                    }else{
                        tabla[i][u] = -1;
                    }
                }
            }
            //Imprime y pregunta el marcador de cada juego.`
            for (int i = 0; i < 5; i++){
                for(int u = 0; u < 5; u++){
                    if(tabla[i][u] == -1){
                        System.out.println(equipos[i] + " VS " + equipos[u]);
                        System.out.println("Marcador 1: ");
                        tabla[i][u] = sc.nextInt();
                        System.out.println("Marcador 2: ");
                        tabla[u][i] = sc.nextInt();
                    }
                }
            }
        }

Thank you for posting your question. It looks like you are only updating one set of data in you 3d array in the loops. With programming there are 1000 ways to achieve a desired end result.

For the simplest path, I would recommend making your points array 3d as well so you can save the scores associated with each team (ie. points[team based on index][points that team has]). Then update the nested loops to update data for your 3d array. One loop should suffice if you update one 3d array based on the outcome from the other 3d array.

to make it interesting you can also use Random.nextInt(numbers to use) to determine the outcome of a game.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM