获取高尔夫分数到一个数组 [英] Getting Golf scores into an array

查看:85
本文介绍了获取高尔夫分数到一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我试图做一个模拟高尔夫记分卡的程序。我坚持用数组...
我有一个洞[] {0,1,...,17}来计数一个18洞球场。但对于数组中的每个元素,我认为我会需要另一个数组,将用户的得分为该洞。
我需要递增洞的成绩(H1S,H2S,3H公司......),因为现在H1S是怎么回事,所以它只是要改写自己的权利,每孔被重用帮助吗?笑反正我迷路了,请帮助我。

Hey guys I'm trying make a program that simulates a scorecard in Golf. I'm stuck with the arrays... I have a hole[] {0, 1, .... ,17} to counts a 18 hole course. But for each element in the array I think I'm going to need another array that takes the user's score for that hole. I need help with incrementing the hole score( h1S, h2S, h3S...) because right now h1S is going to be reused for every hole so it's just going to rewrite itself right? lol anyways I'm lost, help me please.

static int hole[] = new int[18];
{

hole[0] = h1S; // hole Scores..
hole[1] = h2S;
hole[2] = h3S;
hole[3] = h4S;
hole[4] = h5S;
hole[5] = h6S;
hole[6] = h7S;
hole[7] = h8S;
hole[8] = h9S;
hole[9] = h10S;
hole[10] = h11S;
hole[11] = h12S;
hole[12] = h13S;
hole[13] = h14S;
hole[14] = h15S;
hole[15] = h16S;
hole[16] = h17S;
hole[17] = h18S;

}

public static void test1() 
{
    Scanner input = new Scanner(System.in);

    if (numPlayers == 1)
    {
        for (int holeNumber = 1; holeNumber < 19; holeNumber++)
        {
            System.out.println(player1 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();// i need increment h1S somehow *******************
        }
    }

    else if (numPlayers == 2)
    {
        for (int holeNumber = 1; holeNumber < 19; holeNumber++)
        {
            System.out.println(player1 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player2 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();
        }
    }

    else if (numPlayers == 3)
    {
        for (int holeNumber = 1; holeNumber < 19; holeNumber++)
        {
            System.out.println(player1 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player2 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player3 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();
        }
    }

    else if (numPlayers == 4) 
    {
        for (int holeNumber = 1; holeNumber < 19; holeNumber++)
        {
            System.out.println(player1 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player2 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player3 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();

            System.out.println(player4 + ", Enter your hole " + holeNumber + " score.");
            h1S = input.nextInt();
        }
    }


}// end test1

谢谢你们。

推荐答案

你需要一个二维数组(如果你想保持与阵列分数),但你可以通过编程生成它

you do need a 2D array (if you want to keep score with arrays) but you could generate it programatically

int[][] score;

public Scorecard(int players){
  score = new int[18][players];
}

然后,要不断得分,只是记录比分[孔] [playernum] =得分

Envision公司它作为与X轴为空穴和y是玩家的网格。这种方法也可以让你在每个冲程记录,因为你可以用加一得分[孔] [playernum] ++

Envision it as a grid with the x axis being the hole and y being the player. This method also allows you to record at each stroke, since you could increment it with score[hole][playernum]++

这篇关于获取高尔夫分数到一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆