足球比赛的方法 [英] methods for a soccer game

查看:81
本文介绍了足球比赛的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写带有小组赛的足球模拟游戏..到目前为止,我已经完成了团队课程,并且运行良好.现在,我需要在必须使用数组的组类上获得帮助.它包含以下方法:

addTeam()将团队添加到团队数组中

matchPlayed()接受游戏的详细信息并更新团队的详细信息

orderedladder(),根据他们的得分列出球队

以及显示团队排名的stanting()方法.

i am coding a soccer simulation game with group stages.. i have done the team class so far and it is running well. now i need help with the group class where i have to use arrays. It contains the following methods:

addTeam() which adds teams to the team array

matchPlayed() that accepts details of the game and updates the details of the teams

orderedladder() which lists the teams according to their points

and the standings() method which shows the team standings.

How wouil i go about with such a class?

推荐答案

您能更具体一点吗?你有什么问题?你到底在哪里卡住?

通过查看您发布的代码,它有几个问题:
-如果您有一组团队,则将这个变量称为名称"是很奇怪的,您可以简单地选择团队"之类的东西.
-将团队数组的大小硬编码为4是非常有限的.您可以改用LinkedList,这样可以根据需要增加数组(您使用的是Java吗?).
-在带有参数的构造函数中,第二个参数(int[] name)的用途是什么?
-方法teamAdd是错误的:您期望布尔值并返回字符串.此外,您没有将团队添加到团队数组中,而只是将其返回.
Could you please be more specific ? Which problems are you having ? Where are you stuck exactly ?

By looking at the code you posted, there are several issues with it:
- If you have an array of teams, calling this variable "name" is very strange, you could simply go for something like "teams".
- Hardcoding the size of the team array to 4 is very limiting. You could use a LinkedList instead, this way your array can increase depending on the needs (you are using java right ?).
- In the constructor with arguments, what is the purpose of the second argument (int[] name) ?
- The method teamAdd is wrong: you expect a boolean and you return a string. Furthermore you don''t add the team to the array of teams but simply return it.


第一件事,您至少是想了解我在上次答复中建议的观点吗?

我需要一个构造函数来接受组名的值,并使用4个Team对象的空间初始化team数组.

那么,为什么要传递整数数组(name)和count自变量?它们没有任何意义或含义.

需要一个名为addTeam(…)的方法才能将组添加到阵列.这个
方法应传递一个Team对象进行插入.组类是
负责跟踪team数组中有多少Team对象,以确保不会意外替换现有团队.


好吧,现在您的函数什么都不做.提示:您应该使用count成员变量来了解数组中已经有多少支队伍.顺便说一句,您是否需要在某个时候从阵列中删除团队?如果是,那么您需要检查数组是否包含空指针,这意味着这是一个空插槽(并且不要在删除团队时将插槽设置​​为空).

一个名为getOrderedLadder(…)的方法,该方法可以返回一个String,列出
小组中的球队,按照得分的顺序排列.我需要遍历团队对象的数组,比较每个团队的匹配点.
最后一个名为getStandings(...)的方法将执行相同的操作
按照上述方法,但只会返回前两名,以决赛排名"
这些是我需要帮助的方法,如您所见,我无法在我的代码中开始使用它们.


对于这些,您应该已经开始自己做一些事情.我们在这里为您提供帮助,而不是为您做功课.
Fist thing, did you at least try to understand the points I suggested in my previous reply ?

I need to wite a constructor to accept a value for the group name and initialise the team array with space for 4 Team objects.

So, why are you passing an array of integers (name) and the count arguments ? They don''t have any meaning or puprose.

A method called addTeam(…) is required to add a team to the array. This
method should be passed a Team object to insert. the Group class is
responsible for keeping track of how many Team objects are in the teams array, to ensure that existing teams are not accidentally replaced.


Well, for now your function doesn''t do anything. Hint: you should use the count member variable to know how many teams are already in the array. BTW, will you need to remove teams from the array at some point ? If yes, then you need to check if your array contains null pointers, which means this is an empty slot (and don''t dorget to set a slot to null when you remove a team).

A method called getOrderedLadder(…) that can return a String, listing the
teams in the group, in order of number of points scored. I need to iterate through the array of team objects, comparing the match points that each team has.
The last method called getStandings(…) will perform the same actions
as the method above, but will only return the top two teams, for the "final standings"
These are the methods i need help with as you can see i could not begin them in my code.


For these, you should already start doing something on your own. We are here to help you, not do your homework for you.


您好,

听起来像一个不错的项目!

如果您愿意创建课程,然后在这里遇到特定问题,可以在此处获得更多答案. :thumbsup::)
Hi,

Sounds like a nice project!

You will get more answers here if you have a go at creating the class and then come back here with a specific problem or question. :thumbsup: :)


这篇关于足球比赛的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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